Home Answers Viewqa JSP-Servlet How do I change the while loop in this code to the range with range list style display page for a resultSet() in jsp?

 
 


Jerome Lepinski
How do I change the while loop in this code to the range with range list style display page for a resultSet() in jsp?
1 Answer(s)      11 months ago
Posted in : JSP-Servlet

this is count record code

<%@ page language="java" import="java.sql.*" %>
<html>
<head>
<title>Count data from database in jsp</title>
</head>
<body>
<table border="0" width="75%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<h2><font color="#FF0033">Count data from database in jsp</font></h2>
<form method="POST" >
<table border="1" width="75%" cellspacing="0" cellpadding="0" bgcolor="#CCFFCC">

<%
Connection con = null;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
int rows = 0;
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"amar","amar123");
try{
Statement st = con.createStatement();
String query = "select count(*) from user_Register";
ResultSet rs = st.executeQuery(query);

while (rs.next()) {
rows =rs.getInt(1);

%>


<%}

out.println("Total row is = "+rows);
rs.close();
con.close();

}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html> 
View Answers

June 11, 2012 at 5:27 PM


The given code count the number of rows in a database table.

<%@ page language="java" import="java.sql.*" %>
<html>
<head>
<title>Count data from database in jsp</title>
</head>
<body>
<table border="0" width="75%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">
<h2><font color="#FF0033">Count data from database in jsp</font></h2>
<form method="POST" >
<table border="1" width="75%" cellspacing="0" cellpadding="0" bgcolor="#CCFFCC">

<%
Connection con = null;
String url = "jdbc:mysql://192.168.10.211:3306/";
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
int rows = 0;
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"amar","amar123");
try{
Statement st = con.createStatement();
String query = "select count(*) from user_Register";
ResultSet rs = st.executeQuery(query);

if(rs.next()) {
rows =rs.getInt(1);

%>


<%}

out.println("Total row is = "+rows);
rs.close();
con.close();

}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
%>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>









Related Pages:

Ask Questions?

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.