Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. package client;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class DBConnection {
  8.  
  9.     private static final String DB_CONNECTION = "jdbc:mysql://0.0.0.0:3309/jcfxml_db";
  10.     private static final String DB_USER = "root";
  11.     private static final String DB_PASSWORD = "";
  12.  
  13.     private Connection connection;
  14.  
  15.     public DBConnection() {
  16.  
  17.         try {
  18.             Class.forName("com.mysql.jdbc.Driver");
  19.         } catch (ClassNotFoundException e) {
  20.             System.out.println("Where is your MySQL JDBC Driver?");
  21.             e.printStackTrace();
  22.             return;
  23.         }
  24.  
  25.         try {
  26.             this.connection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD);
  27.         } catch (SQLException e) {
  28.             e.printStackTrace();
  29.         }
  30.     }
  31.  
  32.     public Connection getConnection() {
  33.         return connection;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement