DB Connector

Java DB Connector.

JDBCConnector.java
package db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.logging.Level;
import java.util.logging.Logger;

public class JDBCConnector {
    private static Connection con;
    public static Connection getConnection() {
        if (con == null) {
            try {
                Class.forName("com.mysql.jdbc.Driver");
                con = DriverManager.
                        getConnection("jdbc:mysql://localhost:3306/my_db", "root", "123");
            } catch (Exception ex) {
                Logger.getLogger(JDBCConnector.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return con;
    }
}

No comments:

Post a Comment