SQLNonTransientConnectionException:没有当前连接,在我的应用程序中与Derby数据库交互 [英] SQLNonTransientConnectionException: No current connection, in my application while interacting with Derby database
问题描述
我在我的应用程序中实现了德比数据库来保存我的数据,我在Derby数据库中检索结果集形式 select
时获取此异常。
要建立连接,我使用连接字符串作为:
我使用这种方法建立连接:
我在类中声明此方法Connection.java :
public synchronized Connection createConnection {
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);
}
//在连接池创建的新连接
} catch(SQLException e){
final String stackNum = Utility.exceptionHandler(e);
throw new Exception(Exception get during Connection - + e.getMessage());
}
return rescon;
}
我使用这个方法作为创建连接,
private Connection objConnection = null;
objConnectionpool = new Connection(jdbc:derby:+ Folder.getAbsolutePath()+/ myapplication+ sFileName,null,null,org.apache.derby.jdbc.EmbeddedDriver);
objConnection = objConnectionpool.createNewConnection();
我在执行查询时遇到异常:
sQuery =select value,reason from+ TableNm +where fileName ='+ FileName +'AND type ='+ Type +'AND status ='remaining' ;
在处理和交互Derby数据库期间,我们可能会更新从数据库获取数据: p>
在插入数据库之前,我执行setAutoCommit为false
objConnection.setAutoCommit (假);
:
ps = objConnection.prepareStatement(sQuery);
rs = ps.executeQuery();
objConnection.commit();
objConnection.setAutoCommit(true);
我得到异常
java.sql.SQLNonTransientConnectionException:没有当前连接。
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(未知源)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(未知源)
在org .apache.derby.impl.jdbc.Util.newEmbedSQLException(未知源)
at org.apache.derby.impl.jdbc.Util.noCurrentConnection(未知源)
at org.apache.derby.impl .jdbc.EmbedConnection.checkIfClosed(未知源)
at org.apache.derby.impl.jdbc.EmbedConnection.setupContextStack(未知源)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement (未知源)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(未知源)
at com.myapplication.c.aw.a(未知源)
at com .myapplication.c.aw.a(未知来源)
at com.myapplication.main.avd.run(未知来源)
原因:java.sql.SQLException:没有当前连接。
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(未知源)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(未知源)
.. 。另外11个
>
我有同样的问题,在这个示例应用程序中找到我的答案: http://db.apache.org/derby/docs/10.4/devguide/rdevcsecure26537.html
//强制垃圾收集以卸载EmbeddedDriver
//因此可以重新启动Derby
System.gc();
现在可以正常工作。
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
Found this via Google.
I had the same problem and found my answer in this sample application: http://db.apache.org/derby/docs/10.4/devguide/rdevcsecure26537.html
// force garbage collection to unload the EmbeddedDriver // so Derby can be restarted System.gc();
Works perfectly now.
这篇关于SQLNonTransientConnectionException:没有当前连接,在我的应用程序中与Derby数据库交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!