//To know how many records are present in database using jsp
To see total listing of .jsp files first we have to configure the web.xml file present in (E:\Program Files\Apache Software Foundation\Tomcat 6.0\conf) folder.Search the <param-name>listings</param-name> tag and below this tag <param-value>false</param-value>,change the value to true(<param-value>true</param-value>)
Create any folder in (E:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps)and save the below program as totalrecords.jsp
<%@ page import="java.sql.*" %>
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
out.println("Class not found "+ e);
}
out.println("JDBC Class found");
int no_of_rows = 0;
try
{
Connection con = DriverManager.getConnection("jdbc:odbc:mydsn","system","pintu");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM employee");
while (rs.next())
{
no_of_rows++;
}
out.println("There are "+ no_of_rows + " record in the table");
}
catch(SQLException e){
out.println("SQL exception occured" + e);
}
%>