Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Nested resultsets with 1 connection, possible?

 
Sandy Goh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have nested resultsets but I can only use 1 connection to the database.
Is it possible?
Thanks ppl!
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%
String url = "jdbc dbc:company";
Connection conn=null;
String classPath = "sun.jdbc.odbc.JdbcOdbcDriver";
try{
Class.forName(classPath);
conn = DriverManager.getConnection(url,username,password);
}catch(Exception exc){
out.println(exc.toString());
}
Statement stm=null;
Statement stm1=null;
stm1=conn.createStatement();
stm=conn.createStatement();
ResultSet rst=null;
ResultSet rst1=null;

try{
rst=stm.executeQuery("Select DISTINCT comagent from company");

%>

<% while(rst.next()){ %>

<%String agent=rst.getString("comagent");%>
<%rst1=stm1.executeQuery("Select * from company where comagent='"+agent+"' ORDER BY comlead DESC");
rst1.next();%>
<%=rst1.getString("comname")%>
<%=rst1.getString("comlead")%>
<%
}%>

<%
%>
<%}catch(Exception exc){
out.println(exc.toString());
}
stm1.close();
stm.close();
conn.close();

%>
 
Dana Hanna
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but I've found problems with some databases...
 
Sandy Goh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't get what you mean?
 
Dana Hanna
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This did not work for us when using DB2 UDB 6.1 fixpack 3. Upgrading to fixpack 9 fixed it.
I've never had any other problems though. You should be fine, and you are doing everything correctly.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!