我有兩個整數;啓動和停止
最初開始爲0,停止爲1.一旦用戶關閉窗口,開始變爲1.連續運行內部主要方法
我有一個方法可以更新我的JTable;
private void Update_table(){
try{
String sql ="select * from orders ";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
Table_Employee.setModel(DbUtils.resultSetToTableModel(rs));
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
我想連續更新表,但當我在void main方法內部放置一個while循環時,程序崩潰;
void main;
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//Update_table();
while(start<stop)
new Employee_info().Update_table();
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Employee_info.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Employee_info.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Employee_info.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Employee_info.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Employee_info().setVisible(true);
// while(1<2)
// rh.Update_table();
// Update_table();
}
});
}
該erro;
com.mysql.jdbc.exceptions.jdbc4.MySQL SyntaxErrorException: User 12345 already has more than 'max_user_connections' active connections
其中12345是連接到數據庫的用戶名,是因爲我在不同的類中登錄數據庫並運行查詢嗎?
連接類;
import java.sql.*;
import javax.swing.*;
public class javaconnect {
Connection conn=null;
public static Connection ConnecrDb(){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://XXX.com:3306/XXX_pizza","12345 ","XXXX");
// JOptionPane.showMessageDialog(null, "You got connected");
return conn;
}catch(ClassNotFoundException | SQLException e){
JOptionPane.showMessageDialog(null, e);
return null;
}
}
}
Employee_Info類調用javaconnect類來建立連接;
public Employee_info() {
initComponents();
conn=javaconnect.ConnecrDb();
Update_table();
}
錯誤說的是什麼? – BitNinja
剛添加錯誤的原始問題。 – raklar
如何管理連接?更可能的是,你在分配連接時做錯了什麼。 –