錯誤: - 重度:空 com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:數據源被拒絕建立連接的,從服務器消息:「太多的連接」 代碼如下所示在Java JDBC太多連接
try {
BufferedReader br=new BufferedReader(new FileReader(filename));
String line;
String tru="TRUNCATE `project`.`uploadtable`;";
try
{
Statement stmt = Dutil.getConnection().createStatement();
stmt.executeUpdate(tru);
}
catch(Exception e){}
try {
while((line=br.readLine())!=null){
String values[]=line.split("\t");
String[] splitStr = values[1].split(" ");
try {String sql="INSERT INTO `project`.`uploadtable`
(`empid`, `date`, `time`, `in_out_index`) VALUES
('"+values[0]+"', '"+splitStr[0]+"', '"+splitStr[1]+"',
'"+values[3]+"');";
PreparedStatement
pst=Dutil.getConnection().prepareStatement(sql);
pst.executeUpdate();
} catch (SQLException ex) {
System.out.println("Error");
Logger.getLogger(UploadFrame.class.getName()).log(Level.SEVERE,
null, ex);
}
} br.close();
this.dispose();
LogButtonFrame lbf=new LogButtonFrame();
lbf.clockinouttable();
JOptionPane.showMessageDialog(null,"Upload Complete");} catch
(IOException ex) {
Logger.getLogger(UploadFrame.class.getName()).log(Level.SEVERE,
null, ex);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(UploadFrame.class.getName()).log(Level.SEVERE,
null, ex);
}
catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Error");
}
請發表您的代碼不使用圖片 –
您需要在使用後關閉語句和連接,否則它們將保持打開狀態,並且在某些時候您會看到此錯誤。請參閱:[使用JDBC處理SQL語句](https://docs.oracle.com/javase/tutorial/jdbc/basics/processingsqlstatements.html) – Jesper