Guest User

Untitled

a guest
Dec 5th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. public void connect(String FileName, boolean exitOnFail)
  2.     {
  3.         try {
  4.                 this.loadCredentialsFromFile(FileName);
  5.                 this.conn = DriverManager.getConnection("jdbc:mysql://" + this.host + "/" + this.db + "?" + "user=" + this.user  + "&password=" + this.passwd);
  6.                 this.stmt = this.conn.createStatement();
  7.             }
  8.         catch(SQLException ex)
  9.             {
  10.                 // handle any errors
  11.             Main.logging.warning("While connectiong to DB: " + System.getProperty("line.separator")
  12.                                  + "\tSQLException: " + ex.getMessage() + System.getProperty("line.separator")
  13.                                  + "\tSQLState: " + ex.getSQLState() + System.getProperty("line.separator")
  14.                                  + "\tVendorError: " + ex.getErrorCode() + System.getProperty("line.separator")
  15.                                 );
  16.                    
  17.                 if(exitOnFail)
  18.                     {
  19.                         Main.logging.error("Program must shut down due SQL error. (see details in warnings)");
  20.                         System.exit(1);
  21.                     }
  22.             }
  23.         catch(Exception ex)
  24.             {            
  25.                 Main.logging.warning("While connectiong to DB: " + System.getProperty("line.separator")
  26.                                      + "\tException: " + ex.getMessage()
  27.                                     );
  28.  
  29.                 if(exitOnFail)
  30.                     {
  31.                         Main.logging.error("Program must shut down due SQL error. (see details in warnings)");
  32.                         System.exit(1);
  33.                     }
  34.             }
  35.  
  36.     }
Add Comment
Please, Sign In to add comment