Hi
We are facing a tyipcal problem with closing of statements in weblogic
Generally we create statement in try block of the method
and closes in finally block. But if a particualr method is invoked and by the time it reaches finally block, if 2 or more invokes happen simultaneously on that method, then
the statements are not closing(assuming its not reaching finally block). To avoid this we have closed the statement in try block also to avoid open statement problem. It means same code we have written before end of try block(after the usage of statement) and in finally block which is not good practise but no alternative
There is no problem with websphere and jboss only facing the problem with weblogic
Do let us know any remedy is there for this
Regards
B S Reddy
-
Problem with statements in WebLogic (3 messages)
- Posted by: Srinivas Reddy Bijjam
- Posted on: April 28 2005 09:12 EDT
Threaded Messages (3)
- Problem with statements in WebLogic by Srinivas Reddy Bijjam on May 02 2005 00:57 EDT
- Problem with statements in WebLogic by Stefano Crespi on May 03 2005 11:44 EDT
- Problem with statements in WebLogic by sawan parihar on May 10 2005 00:52 EDT
-
Problem with statements in WebLogic[ Go to top ]
- Posted by: Srinivas Reddy Bijjam
- Posted on: May 02 2005 00:57 EDT
- in response to Srinivas Reddy Bijjam
Waiting for the Reply Pls
B S Reddy -
Problem with statements in WebLogic[ Go to top ]
- Posted by: Stefano Crespi
- Posted on: May 03 2005 11:44 EDT
- in response to Srinivas Reddy Bijjam
Hi
try like this
---------------------
package example;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
public class StatementExample {
public StatementExample() {
Context ctx = null;
DataSource ds = null;
Connection conn = null;
Statement stat = null;
ResultSet rs = null;
try {
ctx = new InitialContext();
ds = (DataSource) ctx.lookup ("datasources/NonTxDataSource");
conn = ds.getConnection();
stat = conn.createStatement();
rs = stat.executeQuery("SELECT * FROM DUAL");
rs.getString(1);
}
catch (NamingException ex) {
ex.printStackTrace();
}
catch (SQLException ex) {
ex.printStackTrace();
}
finally {
if (rs != null) {
try { rs.close(); } catch (SQLException ex) { ex.printStackTrace();}
}
if (stat != null) {
try { stat.close(); } catch (SQLException ex) { ex.printStackTrace();}
}
if (conn != null) {
try { conn.close(); } catch (SQLException ex) { ex.printStackTrace();}
}
if (ctx != null) {
try { ctx.close(); } catch (NamingException ex) { ex.printStackTrace();}
}
}
}
}
---------------------
Best regards, Stefano -
Problem with statements in WebLogic[ Go to top ]
- Posted by: sawan parihar
- Posted on: May 10 2005 00:52 EDT
- in response to Srinivas Reddy Bijjam
Hi ,
Try this...
finally
{ try
{
if (statement!= null) {
statement.close();
}
if(connection != null && ! connection.isClosed())
{
connection.close();
}
}
catch (Exception exceptionFinally)
{
throw your application exception;
}
}
I don;t think that the problem statement you have written is the real cause. The finally block will always be executed. Catch the exception and may be you can paste the stack trace here .
Hope that helps.