How to display information from database using drop down list in JSP?
Hi all.
Like the tile above suggest, I'm having difficulty in obtaining the data as well as displaying them in a drop down list.
For example: If i were to have the following in my database:
SerialNoFood
1Bread
2Milk
3Butter
The drop down list should look like the following:
[Bread][\/]
[Milk]
[Butter]
How do i go around coding it in JSP?
Thanks in advance.
C.K
[448 byte] By [
CKeera] at [2007-10-2 21:28:59]

Hai Please try the following code
You have to make some changes according to your system i am using
MSSqlserver Driver change the class name and the connection string
for your need
<HTML>
<HEAD>
<%@ page language="java" import="java.sql.*"%>
<LINK href="../theme/Master.css" rel="stylesheet" type="text/css">
<TITLE>ListDrop.jsp</TITLE>
<%!Connection con;
%>
</HEAD>
<BODY>
<select>
<%
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");\\Here you specify the Class Nale
con = DriverManager
.getConnection(
"jdbc:microsoft:sqlserver://javaserver:1433;DatabaseName=karthi",
"sa", "sa");\\here Connection string
ResultSet rs;
Statement st = con.createStatement();
rs = st.executeQuery("select SerialNo,Food from Foods");
while (rs.next()) {
%>
<option value='<%= rs.getString("SerialNo") %>'><%= rs.getString("Food")%></option>
<%
}
} catch (Exception e) {
e.printStackTrace();
}
%>
</select>
</BODY>
</HTML>