i have this code in main.jsp

<html>
    <head>
        <link rel="stylesheet" href="/bipi/css/bp.css" type="text/css" media="screen"/>
    </head>
    <body>
        <div class="navigator">
            <a id="currenttab" href="/WEB-INF/jsp/main.jsp">Add</a>
            <a href="/bipi/display.jsp">Delete</a>
            <a id="currenttab" href="/WEB-INF/jsp/main.jsp">Main</a>
        </div>

        <%--<%
            String fname = request.getParameter("f_name");
            String fage = request.getParameter("f_age");

            if (fname != null && fage != null ) 
            {
                com.test.gerrard.Insert(fname, fage);
            }
        %>--%>

        <form id="bipiform" method="post" action="/bipi/save.jsp">
            <h1>BiPi Program</h1>

            <table>
                <tr>
                    <td>Nama:</td><td><input type="text" name="f_name" /><br/></td>
                </tr>
                <tr>
                    <td>Age:</td><td><input type="text" name="f_age" /></td>
                    <br>
                    <br>
                </tr>
                <tr>
                    <td>Select</td>
                    <td>
                         <select>
                            <option name="ticket_source" value="0">Pilih Sumber</option>
                            <option value="sumber 1">Sumber 1</option>
                            <option value="sumber 2">Sumber 2</option>
                            <option value="sumber 3">Sumber 3</option>
                        </select>
                    </td>
                </tr>
                <p> </p>
                <tr>
                    <td></td>
                    <td>
                        <input type="submit" value="Submit">
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>

and this code in save.jsp

<%@page import="java.sql.*,java.util.*"%>

<%
    String fname = request.getParameter("f_name");
    String fage = request.getParameter("f_age");
    String source [] = request.getParameterValues("ticket_source");
    if(request.getParameter("ticket_source") != null)
    {
    String[] ItemNames;

    ItemNames = request.getParameterValues("ticket_source");
    for(int i = 0; i < ItemNames.length; i++)
        {
%>
            <tr>
        <td><%= ItemNames[i] %></td>
            </tr>
<%      
        }

    }
%>
<%
    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bipi", "root", "");
        Statement st = con.createStatement();
        int i = st.executeUpdate("insert into bipi_sampel(nama,umur,sumber) values('" + fname + "','"+fage+"','"+source+"')");

        response.sendRedirect("/WEB-INF/jsp/main.jsp");
        out.println("Successful Inserted");

    }     



    catch (Exception e) 
    {

        System.out.print(e);
        e.printStackTrace();
    }
%>

my problem right now is ticket source does not inserted into database.actually i dont know how to insert the dropdown list data into database.can someone teach me please :(

The problem is sumber is varchar feild in table and you are trying to store an array into that
Here the thing is you cant store directly an array into db like php because java is object oriented
If you are trying to store array in Relational database you need further normalization.

can you give me some coding example.i dont know :(

you have to normalize your table ,show your database design

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.