File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Help with JSP Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Help with JSP Page" Watch "Help with JSP Page" New topic

Help with JSP Page

Darren Thomas

Joined: Nov 06, 2003
Posts: 1
keep getting a error java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state. Have opened two database connections. Need to get the username from my users table to be displayed in a table along with info from my items table, hope you can help
Here is the code from the JSP page
Connection conn = DriverManager.getConnection("jdbc dbc:GuestBook");
Statement statement = conn.createStatement();
String sql = "SELECT * FROM Items";
ResultSet rs = statement.executeQuery(sql);
String Email = rs.getString("Email");

Connection conn2 = DriverManager.getConnection("jdbc dbc:GuestBook");
Statement statement2 = conn.createStatement();

String sql1=("SELECT Username FROM Users WHERE Email='"+Email+"'");
ResultSet rs1= statement2.executeQuery(sql1);
while ( {
while ( {
<td><%= rs.getString("Isbn") %></td>
<td><%= rs.getString("Title") %></td>
<td>�<%= rs.getString("Price") %></td>
<td><%= rs1.getString("Username") %></td>
<td width="34%"><%= rs.getString("Email") %></td>
if (statement != null)
if (conn != null)
if (statement2 != null)
if (conn2 != null)
catch (Exception e) {out.print(e);}
Mathias Nilsson
Ranch Hand

Joined: Oct 13, 2003
Posts: 107
String Email = rs.getString("Email");

You must first call before you can do this. There are alot
of other errors in the code but this is the first.
You don't have to make 2 instances of Connection when you are accessing
the same database.
sql1=("SELECT Username FROM Users WHERE Email='"+Email+"'");

You are doing this before the while loop plus you have set the Email variable outside the loop! This means that you will only
get the users with the same email. ( When the code works ) You must have both queries in a loop!
It is better if you do this.

Then you don't have to make two recordSets.
// Hope this helps for a starter
[ November 06, 2003: Message edited by: Mathias Nilsson ]

SCJP2 , MCP( 70-229 ) , Preparing For SCWDC
I agree. Here's the link:
subject: Help with JSP Page
It's not a secret anymore!