JSP connection/ method problem
Hi I have a problem in my jsp and java assignment. I am using a method that returns an integer of number of contacts in my database. this is my code (method).
public int getContactCount() throws SQLException{
int counter = 0;
int counter2 =0;
int total = 0;
String query = "";
query = "SELECT id FROM businesscontact";
String query2 = "SELECT id FROM residentialcontact";
db.connectMethod();
PreparedStatement ps = (PreparedStatement)conn.prepareStatement(query);
ResultSet results = (ResultSet)ps.executeQuery();
while(results.next()){
counter++;
}
PreparedStatement ps2 = (PreparedStatement)conn.prepareStatement(query2);
ResultSet results2 = (ResultSet)ps.executeQuery();
while(results2.next()){
counter++;
}
total = counter + counter2;
db.disconnectMethod();
return total;
}
I am calling that method in my jsp page. This is the code
<%@page import="db.dbOperations"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Number Of Contacts</title>
</head>
<body>
<h2>Total Number Of Contacts</h2>
<% dbOperations db = new dbOperations();
int counter = db.getContactCount();
%>
<h4>The total number of contacts is:<%=counter%></h4>
</body>
</html>
Anyone can help why I have a problem please ?