Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DB;
- import java.sql.*;
- public class DBconnect {
- private static Connection conn = null;
- static Statement stmt = null;
- public static Connection getConnection(){
- if(DBconnect.conn == null){
- createConn();
- }
- return DBconnect.conn;
- }
- private static void createConn()
- {
- try{
- Class.forName("com.mysql.jdbc.Driver");
- String url = "jdbc:mysql:///test";
- String username = "root";
- String pass = "101010";
- DBconnect.conn = DriverManager.getConnection(url, username, pass);
- stmt = conn.createStatement();
- }
- catch (ClassNotFoundException e){
- System.out.println(e.getMessage());
- System.exit(0);
- }
- catch (SQLException e){
- System.out.println(e.getMessage());
- System.exit(0);
- }
- catch (Exception e){
- }
- }
- }
Add Comment
Please, Sign In to add comment