Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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)      2 years and 6 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> 

Advertisement
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 Tutorials/Questions & Answers:
 

 

 

DMCA.com