How to display all the Select values from the MySQL database table in where condition= In JSP?

How to display all the Select values from the MySQL database table in where condition= In JSP?

**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>
View Answers

July 29, 2011 at 3:39 PM

<%@ 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>









Related Tutorials/Questions & Answers:
How to display all the Select values from the MySQL database table in where condition= In JSP?
How to display all the rows in JSP ,MySQL select condition statement IN dept_table
Advertisements
how to display values from database into table using jsp
How to Display values from databse into table
how to display a table from database using servlet
mysql select into table from another table example
PHP WHERE clause example to fetch records from Database Table
Select data from Table in Database
How to display data fom MySQL DataBase-table in to JSP file by submitting a value in combobox.
how to count unique and duplicate values from one table in mysql?
Inserting values in MySQL database table
how to store multiple values from drop down in database where i am using java struts 1.3
how to display image and text in single jsp page from the mysql database
Mysql Date in where clause
how to display data from mysql table in text box using jsp??
How to insert and update all column values of database from jtable.
How to insert and update all column values of database from jtable.
how to display the database values in pdf format
How to insert and update all column values of database from jtable.
How to use next and previous button(or href) for database table that is retrieved from MySQL DB using jsp,jstl,javascript
Select Employee and display data from access database in a jtable
How to Dragging and dropping HTML table row to another position(In Jsp) and save the new position (values) also in database(MySql)?
MySQL PHP Query delete
Add values of drop down menu( select option) to mysql table
MySql Databse query to fetch results from database and display it in HTML File
display data from a table in Access Database in a HTML page
Deleting All Rows From the database Table
how to select the row value that was retrived from the database ?
how to select the row value that was retrived from the database ?
Display Data from Database in JSP
Mysql where
Display Blob(Image) from Mysql table using JSP
Deleting a Table from Database
MySQL Select Statement
How to use next and previous button(or href) for database table that is retrieved from MySQL DB.
how to display records from database
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.
unable to display table data on JSP page that is coming from mysql and servlet.
Retrieving All Rows from a Database Table
how to upload an image from a jsp page to a mysql database table using jsp
Query to insert values in the empty fields in the last row of a table in Mysql database?
image is display from path of mysql database
Dynamic retrieval od data from database and display it in the table at jsp
deleting all records from a table in mysql
deleting all records from a table in mysql
MySQL PHP Search
MySQL Nested Select Example
Mysql date equal
Select from select list + display

Ads