• Post Reply Bookmark Topic Watch Topic
  • New Topic

store selected value from drop down list to database

 
bhavana dixit
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to store the selected value from drop down list to mysql database...what should I do??
I have written the following code

<%@ page import="java.sql.*" %>
<%ResultSet resultset =null;%>

<HTML>
<HEAD>
<TITLE>Assessment Questionnaire</TITLE>
</HEAD>



<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/city?user=root&password=");
Statement statement = connection.createStatement() ;
resultset =statement.executeQuery("select * from new") ;
%>

<center>
<h1> Assessment Questionnaire</h1>
<%resultset.next(); %>

<%do { %>




<%out.println(resultset.getInt(1));%>
    
<select>
<option><%= resultset.getInt(2)%></option>
<option><%= resultset.getInt(3)%></option>
<option><%= resultset.getInt(4)%></option>

</select>
<% }while(resultset.next()); %>
</center>

<%

}
catch(Exception e)
{
out.println("wrong entry"+e);
}
%>

</BODY>
</HTML>

what should i do to store the value selected from dropdown list...I have multiple dropdown list on a single page..
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35709
408
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first step is to add <form> tags on that JSP and submit to a URL. Then you can create a servlet that calls request.getParameters() and reads the value. From then on, it is JDBC.

Note that it is considered bad practice to have Java code in a JSP. Consider splitting the existing code out into a regular Java class. Also, you want to close database resources in a finally block so you don't have a resource leak.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!