C
carmelo
Hi everybody,
I'm developing a simple JSP web app, which needs to execute 2 nested
sql queries:
1) executing a SELECT sql query, for extracting "base" data from
myTable_base
2) for each record found with the (1) query, execute a query for
extracting "special" data from myTable_special
I used this code:
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
try
{
String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(DRIVER);
conn=DriverManager.getConnection("jdbcdbc:Sirx2;ServerName=192.168.1.50.1543;ServerDSN=sirx41","sirx","sirx");
query="SELECT * from myTable_base";
stmt=conn.createStatement();
rs = stmt.executeQuery(query);
while (rs.next())
{
field = rs.getString("field_base");
query="SELECT * from myTable_special";
Statement stmt2=null;
ResultSet rs2=null;
try
{
stmt2=conn.createStatement();
rs2 = stmt2.executeQuery(query);
//ottiene il dato
if(rs2.next())
{
field = rs.getString("field_special");
}
}
catch(Exception e)
{
out.println(e);
}
finally
{
try
{
if (rs2 != null)
rs2.close();
}
catch (Exception e)
{
out.println(e);
}
try
{
if (stmt2 != null)
stmt2.close();
}
catch (Exception e)
{
out.println(e);
}
}
out.println("Data: "+field);
}
}
catch(Exception e)
{
out.println(e);
}
finally
{
try
{
if (rs != null)
rs.close();
}
catch (Exception e)
{
out.println(e);
}
try
{
if (stmt != null)
stmt.close();
}
catch (Exception e)
{
out.println(e);
}
try
{
if (conn != null)
conn.close();
}
catch (SQLException e)
{
out.println(e);
}
}
It seems that the external while loop ends when the inner IF condition
is true...
I hope in your help
Thank you very much in advance
Carmelo
I'm developing a simple JSP web app, which needs to execute 2 nested
sql queries:
1) executing a SELECT sql query, for extracting "base" data from
myTable_base
2) for each record found with the (1) query, execute a query for
extracting "special" data from myTable_special
I used this code:
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
try
{
String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(DRIVER);
conn=DriverManager.getConnection("jdbcdbc:Sirx2;ServerName=192.168.1.50.1543;ServerDSN=sirx41","sirx","sirx");
query="SELECT * from myTable_base";
stmt=conn.createStatement();
rs = stmt.executeQuery(query);
while (rs.next())
{
field = rs.getString("field_base");
query="SELECT * from myTable_special";
Statement stmt2=null;
ResultSet rs2=null;
try
{
stmt2=conn.createStatement();
rs2 = stmt2.executeQuery(query);
//ottiene il dato
if(rs2.next())
{
field = rs.getString("field_special");
}
}
catch(Exception e)
{
out.println(e);
}
finally
{
try
{
if (rs2 != null)
rs2.close();
}
catch (Exception e)
{
out.println(e);
}
try
{
if (stmt2 != null)
stmt2.close();
}
catch (Exception e)
{
out.println(e);
}
}
out.println("Data: "+field);
}
}
catch(Exception e)
{
out.println(e);
}
finally
{
try
{
if (rs != null)
rs.close();
}
catch (Exception e)
{
out.println(e);
}
try
{
if (stmt != null)
stmt.close();
}
catch (Exception e)
{
out.println(e);
}
try
{
if (conn != null)
conn.close();
}
catch (SQLException e)
{
out.println(e);
}
}
It seems that the external while loop ends when the inner IF condition
is true...
I hope in your help
Thank you very much in advance
Carmelo