This content has been marked as final.
Show 3 replies
-
1. Re: 3.20 nested query warning about open connections
davidjencks Apr 23, 2003 6:45 PM (in response to aarti)"davidjencks" wrote:
Looks like it should work to me. Can you show the stack trace and more of your code? I assume the call to method2 is inside the loop? I also assume it is a direct method call rather than through the ejb interface? -
2. Re: 3.20 nested query warning about open connections
aarti May 1, 2003 4:21 PM (in response to aarti)"aarti" wrote:
This happens with any nested query:
This is the warning I am getting
18:14:55,080 WARN [jdbc.WrappedConnection] Closing a statement you left open, please do your own housekeeping
My source code looks like this:
public void updateCheckOrderStatus(ScheduledOrderVO scheduledOrderVO)
{
Connection con = null;
try
{
con = SQLDAOFactory.getConnection();
Statement stmt = con.createStatement();
MessageFormat mf = new MessageFormat(UPDATE_CHECK_ORDER);
Object[] arguments =
{
new String("'" + StringUtils.replace(scheduledOrderVO.checkedBy.userId.trim(), "'", "''") + "'"),
new String("'" + StringUtils.replace(scheduledOrderVO.patientKeyVO.patientId.trim(), "'", "''") + "'"),
new String("'" + StringUtils.replace(scheduledOrderVO.orderId.trim(), "'", "''") + "'"),
new Integer(scheduledOrderVO.orderAdminNum.trim())};
stmt.executeUpdate(mf.format(arguments));
insertVerifiedOrder(scheduledOrderVO);
stmt.close();
con.close();
}
catch (SQLException se)
{
throw new LoggableSystemException(se, log, Level.ERROR, null);
}
finally
{
try
{
if (con != null)
{
con.close();
}
}
catch (SQLException e)
{
}
}
private void insertVerifiedOrder(ScheduledOrderVO scheduledOrderVO)
{
Connection con = null;
try
{
con = SQLDAOFactory.getConnection();
Statement stmt = con.createStatement();
MessageFormat mf = null;
// Get the solution information for order
mf = new MessageFormat(SELECT_SOLUTION_BY_ORDER);
Object[] solutionArgs =
{ new String("'" + scheduledOrderVO.patientKeyVO.patientId + "'"),
new String("'" + scheduledOrderVO.orderId + "'")};
ResultSet rs = stmt.executeQuery(mf.format(solutionArgs));
if (rs != null && rs.next())
{
boolean isSolution = rs.getInt(1) == 1 ? true : false;
if (isSolution)
// For a solution order the dose_val_min and dose_units are copied to the volume fields leaving the dose min, max and units null.
mf = new MessageFormat(INSERT_VERIFIED_ORDER_WITH_VOLUME);
else
//For a non-solution order the dose_val_min, max and units are copied to the same fields and the volume fields are null.
mf = new MessageFormat(INSERT_VERIFIED_ORDER);
Object[] args =
{
new String("'" + scheduledOrderVO.patientKeyVO.patientId + "'"),
new String("'" + scheduledOrderVO.orderId + "'"),
new Integer(scheduledOrderVO.orderAdminNum)};
System.out.println("EXECUTING:" + mf.format(args));
int rows = stmt.executeUpdate(mf.format(args));
if (rows < 1)
throw new EJBException(
" Error inserting Secure Order for patient"
+ scheduledOrderVO.patientKeyVO.patientId
+ " and order "
+ scheduledOrderVO.orderId);
// For a solution order add the solution information in the secure order solution table
if (isSolution)
{
Statement stmt2 = con.createStatement();
MessageFormat mf2 = new MessageFormat(INSERT_VERIFIED_ORDER_SOLUTION);
System.out.println("EXECUTING:" + mf2.format(args));
rows = stmt.executeUpdate(mf2.format(args));
}
}
else
throw new EJBException(" InsertVerifiedOrder: No Order found ");
}
catch (Exception e)
{
throw new LoggableSystemException(e, log, Level.ERROR, null);
}
finally
{
try
{
if (con != null)
{
con.close();
}
}
catch (SQLException e)
{
}
}
} -
3. Re: 3.20 nested query warning about open connections
jonlee May 7, 2003 3:57 AM (in response to aarti)"jonlee" wrote:
Actually, the problem isn't about releasing connections. JBoss is complaining that you don't close your statements before you release the connection. In the first method, you have a stmt.close() - you should make sure that you try to do this even if things go awry when you execute statements.
In the second method, you create two statements but don't have any code to close either.