连接未成功关闭?

时间:2013-10-01 17:30:09

标签: java sql-server-2008 hibernate jdbc

在我将最新版本的软件上传到服务器后,我们的一个应用程序开始失败。 它访问了一些共享表,但我无法弄清楚我是否做错了什么以及是不是我的错。

在我的测试环境中,一切都很顺利,但在我更新主服务器上的表格时,我发现其中一些似乎被锁定了,就像还有一个操作未决的情况一样。

在Activity Monitor中杀死我的进程后,一切都很好。这有点奇怪。我使用普通的JDBC,有时使用Hibernate进行操作。 我检查了几次,我总是像这样处理JDBC-Connections:

Connection c = null;
Statement s = null;//Sometimes PreparedStatement
ResultSet rs = null;
try{
//OPERATIONS
}
catch{
//Handling
}finally{
Mycon.disconnect(rs,ps,c);
}

Mycon-Class是一个静态类,只支持这些基本的东西......

public static void disconnect(ResultSet resultSet, PreparedStatement ps, Connection connection) {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
            } // nothing we can do
        }
        if (ps != null) {
            try {
                ps.close();
            } catch (SQLException e) {
            } // nothing we can do
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
            } // nothing we can do
        }
    }

对于Hibernate,它通常更容易。然后我只使用一个简单的:

try{
    SessionFactory factory = HibernateUtil.getSessionFactory();
    Session hsession = factory.openSession();
    Transaction tx = hsession.beginTransaction();
//Operations
tx.commit;
}catch(...){}
finally{
try{
hsession.close;
}catch(...){}
}

我使用Apache Tomcat 7来处理我的连接,所以我认为没有必要担心连接。

无论如何 - 例如我的4个过程:

Server_Monitor_View

第一个和第二个来自服务器管理器。

3详细显示:

SELECT W_ID, Comment, Date FROM Buran.dbo.Object WHERE right(convert(varchar, Date, 106), 8) like ''

在我看来哪个不应该存在。我曾多次使用这句话而另一份声明却关闭了它:

innerstat = null;
inners = null;
innerswert = "";
try {
    innerstat = c.createStatement();
    inners = innerstat.executeQuery("SELECT W_ID, Comment, Date FROM Buran.dbo.Object WHERE right(convert(varchar, Date, 106), 8) like '" + innerswert + "'");

    while (inners.next()) {
        innerswert = inners.getString(1);
        out.write("<option value='" + inners.getInt("W_ID") + "'>");
        out.write(innerswert);
        out.write("</option>");
    }
} catch (SQLException sqle2) {
    out.write(sqle2.toString());
    out.write(sqle2.getLocalizedMessage());
    sqle2.printStackTrace();

} finally {
    Mycon.disconnect(inners, innerstat);
}

我只是在解释那些不存在的东西吗?服务器日志很好,我的代码可以正常运行而不会抛出异常。您认为可能是什么错误(如果有的话?)

0 个答案:

没有答案
相关问题