Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package project_try2;
  2. import java.sql.*;
  3. public class DBCONNECT {
  4.     private static DBCONNECT instance = new DBCONNECT() ;
  5.     public static final String url="jdbc:mysql://localhost/car_ser" ;
  6.     public static final String USER_NAME="root" ;
  7.     public static final String PASSWORD="" ;  
  8.     public static final String DRIVER_CLASS="com.mysql.jdbc.Driver";
  9.    
  10.      private  DBCONNECT()
  11.      {
  12.          try{
  13.              Class.forName(DRIVER_CLASS) ;
  14.          }catch(ClassNotFoundException e)
  15.          {
  16.              e.printStackTrace() ;
  17.              
  18.          }  
  19.      }
  20.      private  Connection Createconnection()  
  21.      {  
  22.          Connection connection = null ;  
  23.          
  24.          try {
  25.              connection = DriverManager.getConnection(url, USER_NAME, PASSWORD);
  26.          
  27.          }catch(SQLException e){
  28.             System.out.println("connection faild ") ;
  29.          }
  30.           return connection;
  31.     }
  32.     public static Connection getConnection(){
  33.         return instance.Createconnection();
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement