database SQLNonTransientConnectionException:在与 Derby 数据库交互时在我的应用程序中没有当前连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6172930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLNonTransientConnectionException: No current connection, in my application while interacting with Derby database
提问by user609621
I implemented derby data base in my application to save my data,and I am getting this exception in retrieval of result set form selectquery in Derby database.
To establish the connection I use connection string as:
我在我的应用程序中实现了 derby 数据库来保存我的数据,我select在 Derby 数据库中检索结果集表单查询时遇到了这个异常。要建立连接,我使用连接字符串作为:
I establish connection using this method:
我使用这种方法建立连接:
I declare this method in class Connection.java:
我在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:
在处理和与 Derby 数据库交互期间,我们可能会更新以及从数据库中获取数据:
I perform setAutoCommit as false before inserting in the database
在插入数据库之前,我将 setAutoCommit 执行为 false
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
回答by Whired
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
我遇到了同样的问题,并在此示例应用程序中找到了答案: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();
// force garbage collection to unload the EmbeddedDriver // so Derby can be restarted System.gc();
Works perfectly now.
现在完美运行。

