Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package application;
- import java.sql.*;
- public class JDBCMySQLConnection {
- private static JDBCMySQLConnection instance = new JDBCMySQLConnection();
- //URL to the databse
- /*where jdbc is essential
- * mysql is the dbms
- * localhost: the host of the server
- * jdbcdb: the name of the databse
- */
- public static final String URL="jdbc:mysql://localhost/jdbcdb";
- //User name to the database
- public static final String USER_NAME="";
- //Password
- public static final String PASSWORD="";
- //Driver : it comes with the jar file
- public static final String DRIVER_CLASS="com.mysql.jdbc.Driver";
- private JDBCMySQLConnection(){
- try{
- Class.forName(DRIVER_CLASS);
- }catch(ClassNotFoundException e){
- e.printStackTrace();
- }
- }
- private Connection createConnection(){
- Connection connection = null;
- try{
- connection = DriverManager.getConnection(URL, USER_NAME, PASSWORD);
- }catch(SQLException e){
- System.out.println("Error Unable to connect to DB");
- }
- return connection;
- }
- public static Connection getConnection(){
- return instance.createConnection();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement