• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Help with JSP Page

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);}
%>
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic