Java执行程序挂起
我正在执行一个非常简单的SQL,当我在SQLServerManagementStudio中运行时,只需几秒钟。 但当我使用JDBC在java中运行时,它会冻结。内存使用量从34MB增加到280MBJava执行程序挂起,java,jdbc,Java,Jdbc,我正在执行一个非常简单的SQL,当我在SQLServerManagementStudio中运行时,只需几秒钟。 但当我使用JDBC在java中运行时,它会冻结。内存使用量从34MB增加到280MB public int size() { int lines = 0; string StringSize = "SELECT COUNT(BO_Numseq) FROM dbo.BOLETO"; try { Statement statementL = conn
public int size() {
int lines = 0;
string StringSize = "SELECT COUNT(BO_Numseq) FROM dbo.BOLETO";
try {
Statement statementL = connection.createStatement();
ResultSet rsLocal = statementL.executeQuery(StringSize);
rsLocal.next();
int size = rsLocal.getInt(1);
resetConnexion();
return size;
} catch (SQLException ex) {
Logger.getLogger(ModelTratamentoBoleto.class.getName()).log(Level.SEVERE, null, ex);
}
return lines;
public void resetConnexion() {
try {
connection = MSFConstants.controleur.getConnectionAutomat().getCnx();
statement = connection.createStatement();
rs = statement.executeQuery(stringCommand);
} catch (SQLException ex) {
Logger.getLogger(ModelTratamentoBoleto.class.getName()).log(Level.SEVERE, null, ex);
}
}
public class ConnectionAutomat {
private Connection cnx;
private String stringConnection;
public ConnectionAutomat() {
// System.out.println("start ConnectionAutomat");
MSFConstants.versionBdD = "NV02.06c";
String sysUserName = System.getProperty("user.name");
String activeBase="Automat";
if(MSFConstants.SWtestSandBox){
activeBase="AutomatSandbox";
}
stringConnection = "jdbc:sqlserver://localhost;"
+ "databaseName="+activeBase+";user="
+ MSFConstants.user.getLogonAutomat()
+ ";password="
+ MSFConstants.user.getPassAutomat();
}
// System.out.println("ConnectionAutomat stringConnection " + stringConnection);
try {
cnx = DriverManager.getConnection(stringConnection);
// System.out.println("ConnectionAutomat connection");
} catch (SQLException ex) {
// System.out.println("ConnectionAutomat erreur");
javax.swing.JOptionPane.showMessageDialog(null,
"Error ");
// Logger.getLogger(ConnectionAutomat.class.getName()).log(Level.SEVERE, null, ex);
MSFConstants.controleur.fermetureApplication();
}
}
public Connection getCnx() {
return cnx;
}
它挂起在“ResultSet rsLocal=statementL.executeQuery(StringSize);”行中
我在Java Update 8 25上运行这个jar,所以我认为这不是版本问题
重要的信息是,它一直运行到上周,代码中没有任何更改
我能做些什么来让它工作?我完全迷路了,不太懂java
谢谢大家! 这似乎更像是一个数据问题。请尝试从DB端分析该表,然后再次运行代码。此处有标识符,如
StringSize
和resetConnexion()
,但您尚未向我们显示代码,因此我们不知道它们的作用。请修复此问题。很抱歉但它冻结在“ResultSet rsLocal=statementL.executeQuery(StringSize);”行,因此永远不会到达resetConnexion()。让我们看看连接的代码。和语句l
。你真的是指语句
?但是如果resetConnexion()永远无法到达,为什么需要它呢?它冻结在“ResultSet rsLocal=statementL.executeQuery(StringSize)”;您的语句可能没有更改,也许数据库现在有更多的行?或者数据库服务器有一些问题。无论如何,试着启用JDBC调试日志记录,看看这是怎么说的。这是可能的。但数据如何冻结并使用我的代码的高内存使用率呢?所有行都有大小限制,因此它们都很小。