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"%>
Total Number Of Contacts
<% dbOperations db = new dbOperations();
int counter = db.getContactCount();
%>
The total number of contacts is:<%=counter%>
Anyone can help why I have a problem please ?
Replies
Know the answer? Post it — somebody with the same question will find it here.