
**Hi in jsp,SQL select statement,i am unable to display all the select values from MySQL DB**
only first value is displayed in the jsp file.
@select * from table dept where dept_no=10;"
jsp code i have used is:
-----------------
<TABLE BORDER="1">
<TR>
<TH>dept_name</TH>
<TH>dept_no</TH>
</TR>
<TR>
<TD> <%= resultset.getString(1) %> </TD>
<TD> <%= resultset.getString(2) %> </TD>
------------------
it is displaying only the fist value that satisfied the condition,but i want all the rows to be displayed in the jsp file.
Plz help..thanks in advance.
</TR>

<%@ page import="java.sql.*" %>
<html>
<body>
<br><br>
<form method="post" name="form">
<table border="1">
<tr><th>DEPT NO</th><th>DEPT NAME</th></tr>
<%
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String userName ="root";
String password="root";
int sumcount=0;
Statement st;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db,userName,password);
String query = "select * from dept";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>
<%
while(rs.next()){
%>
<tr><td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
</tr>
<%
}
%>
<%
}
catch(Exception e){
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.