Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getting exception SQLNonTransientConnectionException: No current connection

857930May 30 2011 — edited May 31 2011
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:</br>

I establish connection using this method:
I declare this method in class "connection.java":</br>
<b>
<p>
[

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;
}

]
</p></b>

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

<p><b>

[

private Connection objConnection = null;

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

objConnection = objConnectionpool.createNewConnection();
]

</p> </b> </br>
I am getting exception in execution of Query:</br>


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:</br>
I perform setAutoCommit as false before inserting in the database </br>

<b>"objConnection.setAutoCommit(false);"</b>

after insertion:<p><b>

ps = objConnection.prepareStatement(sQuery);

rs = ps.executeQuery();
objConnection.commit();
objConnection.setAutoCommit(true);</p></b>



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

Edited by: 854927 on May 30, 2011 11:32 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 28 2011
Added on May 30 2011
2 comments
2,195 views