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 :(