File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with JSP Page

 
Darren Thomas
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
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");

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
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 (rs1.next()) {
while (rs.next()) {
%>
<tr>
<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>
</tr>
<%
}
%>
<%
if (statement != null)
statement.close();
if (conn != null)
conn.close();
if (statement2 != null)
statement2.close();
if (conn2 != null)
conn2.close();
}
}
catch (Exception e) {out.print(e);}
%>
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String Email = rs.getString("Email");


You must first call rs.next() 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 ]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic