Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
No replies
SystemAdmin
SystemAdmin
9224 Posts
ACCEPTED ANSWER

Pinned topic SQLNonTransientConnectionException: No current connection

‏2011-07-14T06:16:40Z |
NOTE: this thread was migrated from projectzero.org. Some content and formatting may have been lost in the move.


Originally posted by projectzero userid: keerti - f=4&t=2328#p9431
Hello
Please suggest a solution i need it in my application
I do following operations
getting exception SQLNonTransientConnectionException: No current connection
Posted: May 29, 2011 11:30 PM
derby

Click to report abuse... Click to reply to this thread Reply
Hello,

I implemented derby data base in my application to save my data,and i am getting this exception in retrieval of result set form "select" query in derby database.
To establish the connection i use connection string as:

I establish connection using this method:
I declare this method in class "connection.java":

[

public synchronized Connection createConnection() throws Exception {

Connection rescon = null;

try {
if (this.dbuser == null) {

rescon = DriverManager.getConnection(this.URI + ";create=true");

} else {

rescon = DriverManager.getConnection(this.URI + ";create=true",
this.dbuser, this.dbpass);
}
// new connection in connection pool created

} catch (SQLException e) {
final String stackNum = Utility.exceptionHandler(e);

throw new Exception("Exception get during Connection - " + e.getMessage());
}
return rescon;
}

]

I used this method as and create connection, create connection during intraction using string:



[

private Connection objConnection = null;

objConnectionpool = new Connection("jdbc:derby:" + Folder.getAbsolutePath() + "/myapplication" + sFileName, null, null, "org.apache.derby.jdbc.EmbeddedDriver");

objConnection = objConnectionpool.createNewConnection();
]


I am getting exception in execution of Query:

sQuery = "select value,reason from " + TableNm + " where fileName ='" + FileName + "' AND type='"Type"' AND status ='remaining'";

during processing and interaction with derby database we might update as well get the data from the database:
I perform setAutoCommit as false before inserting in the database

"objConnection.setAutoCommit(false);"

after insertion:


ps = objConnection.prepareStatement(sQuery);

rs = ps.executeQuery();
objConnection.commit();
objConnection.setAutoCommit(true);

I am getting Exception as

java.sql.SQLNonTransientConnectionException: No current connection.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.noCurrentConnection(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.checkIfClosed(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.setupContextStack(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at com.myapplication.c.aw.a(Unknown Source)
at com.myapplication.c.aw.a(Unknown Source)
at com.myapplication.main.avd.run(Unknown Source)
Caused by: java.sql.SQLException: No current connection.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 11 more

Please suggest some solution as i m stuck in this problem..
Thanks in advance..
Keerti