【发布时间】:2017-06-23 11:40:39
【问题描述】:
错误:- 严重:空 com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:数据源拒绝建立连接,来自服务器的消息:“连接太多” 代码如下所示
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");
}
【问题讨论】:
-
请发布您的代码不要使用图片
-
您需要在使用完语句和连接后关闭它们,否则它们将保持打开状态,并且在某些时候您会收到此错误。见:Processing SQL Statements with JDBC