There is time needed where we want to know how many rows are there in table.
For that we want to check the database by providing select * from table command instead we can get no of rows in jsp page itself.
Create a table named users with one column name for ex
create table users(name varchar(100));
insert into users values('http://s2sgateway.com');
insert into users values('http://sitepromoter.co.cc');
Then save the following code in a file named count.jsp and create a web.xml file with in web-inf folder.
<%@ page import="java.sql.*" %>
<%
int count=0;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost/s2sgateway", "username", "password");
PreparedStatement p = con.prepareStatement("");
ResultSet rs = p.executeQuery("select count(*) from users");
while (rs.next()){
count = rs.getInt(1);
}
out.println("The Total Count is " + count);
}
catch(Exception e){
out.println("The exception is " + e);
%>
Now run the program you will get count as 2 any doubt ask us happy coding