Page 222 - 3-1
P. 222

package MDP;


              import java.sql.DriverManager;
              import java.sql.Connection;
              import java.sql.SQLException;
              import MDP.*;
              import com.mysql.jdbc.*;


              public class Makeconnection {
                      private static Makeconnection mc = new Makeconnection();
                      private static Connection conn = null;


                      final String DRIVER = "com.mysql.jdbc.Driver";
                      final String URL = "jdbc:mysql://localhost:3306/";
                      final String USER = "root";
                      final String PASSWORD = "raspberry";


                      public static Makeconnection getInstance(){
                              return mc;
                      }


                      public Connection getConnection(){
                              if(conn == null){
                                      try{
                                              Class.forName(DRIVER);
                                              conn      =      DriverManager.getConnection(URL,      USER,
              PASSWORD);


                                      }catch(ClassNotFoundException e){
                                              e.printStackTrace();
                                      }catch(SQLException e){
                                              e.printStackTrace();
                                      }
                              }


                              return conn;
                      }
              }







                                                         - 222 -
   217   218   219   220   221   222   223   224   225   226   227