public class SetupConnection{
public static Statement setCon(){
Connection con=null;
Statement st=null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/zomatocrm","root","");
st = con.createStatement();
}
catch(ConnectException err){
JOptionPane.showMessageDialog(null, "Connection refused!!!");
System.out.println(err.getMessage());
}
catch(Exception e){
System.out.println(e.getMessage());
}
return st;
}
異常從來沒有在try語句
在catch(ConnectException){
線即將到來的身體扔。在try塊
只要刪除該catch條款。正如例外說的那樣,這個異常永遠不會從try體內拋出。 –