我正在执行一个非常简单的SQL,当我在SQL Server Management Studio中运行时,只需要几秒钟。但是当我使用JDBC在java中运行时,它就会冻结。内存使用量从34MB增加到280MB。
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 Update825上运行这个jar,所以我不认为这是版本问题。
重要的信息是,直到上周,它都运行得很好,代码中没有任何变化。
我能做些什么来让它工作呢?我完全迷失了方向,对java也不太了解。
谢谢!
发布于 2014-11-29 01:40:09
这似乎更多的是一个数据问题。尝试从DB端分析该表,然后再次运行代码。
https://stackoverflow.com/questions/27193250
复制相似问题