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

Ads
 

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>

Ads









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
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.
Select data from Table in Database
how to count unique and duplicate values from one table in mysql?
PHP WHERE clause example to fetch records from Database Table
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.
how to store multiple values from drop down in database where i am using java struts 1.3
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)?
how to select the row value that was retrived from the database ?
how to select the row value that was retrived from the database ?
Select Employee and display data from access database in a jtable
how to upload an image from a jsp page to a mysql database table using jsp
MySQL PHP Query delete
How to use next and previous button(or href) for database table that is retrieved from MySQL DB.
how to display records from database
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
how to fetch data from mysql database table and draw a bar chart on that data using in jsp
Add values of drop down menu( select option) to mysql table
deleting all records from a table in mysql
deleting all records from a table in mysql

Ads