TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mark Fenech
NA
82
69.2k
JSP connection/ method problem
Jan 5 2012 3:49 PM
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 ?
Reply
Answers (
0
)
Do i prevent the output of my JSP.........
API documentation