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
How to display data fom MySQL DataBase-table in to JSP file by submitting a value in combobox.
PHP WHERE clause example to fetch records from Database Table
Select data from Table in Database
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
how to display data from mysql table in text box using jsp??
how to display the database values in pdf format
How to insert and update all column values of database from jtable.
How to insert and update all column values of database from jtable.
Mysql Date in where clause
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
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
Select Employee and display data from access database in a jtable
Add values of drop down menu( select option) to mysql 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 a table in Access Database in a HTML page
MySql Databse query to fetch results from database and display it in HTML File
How to use next and previous button(or href) for database table that is retrieved from MySQL DB.
Display Data from Database in JSP
Mysql where
how to upload an image from a jsp page to a mysql database table using jsp
how to display records from database
Deleting All Rows From the database Table
Deleting a Table from Database
Display Blob(Image) from Mysql table using JSP
MySQL Select Statement
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
Query to insert values in the empty fields in the last row of a table in Mysql database?
deleting all records from a table in mysql
deleting all records from a table in mysql
how to fetch data from mysql database table and draw a bar chart on that data using in jsp
MySQL PHP Search
Dynamic retrieval od data from database and display it in the table at jsp
image is display from path of mysql database
Mysql date equal
how to display data from database in jsp

Ads