daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Oct 17th, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package mysqlConnection;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class LoadDriver {
  8.     private static String url = "jdbc:mysql://localhost:3306/patternframework";    
  9.     private static String driverName = "com.mysql.jdbc.Driver";  
  10.     private static String username = "root";  
  11.     private static String password = "rootme";
  12.     private static Connection con;
  13.  
  14.     public static Connection getConnection() {
  15.         try {
  16.             Class.forName(driverName);
  17.             try {
  18.                 con = DriverManager.getConnection(url, username, password);
  19.             } catch (SQLException ex) {
  20.                 // log an exception. fro example:
  21.                 System.out.println("Failed to create the database connection.");
  22.             }
  23.         } catch (ClassNotFoundException ex) {
  24.             // log an exception. for example:
  25.             System.out.println("Driver not found.");
  26.         }
  27.         return con;
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top