Created
August 13, 2013 04:43
-
-
Save 1ik/6217962 to your computer and use it in GitHub Desktop.
JDBC Connector class for java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jdbc; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
import java.util.ArrayList; | |
public class connector { | |
private static Connection conn=null; | |
public static Connection getConnection(){ | |
if(conn==null)connect(); | |
return conn; | |
} | |
private static void connect(){ | |
try { | |
Class.forName("com.mysql.jdbc.Driver"); | |
conn = DriverManager.getConnection("jdbc:mysql://localhost/mysql?user=root&password="); | |
System.out.println("connected"); | |
} catch (SQLException | ClassNotFoundException e) { | |
e.printStackTrace(); | |
System.err.println("connection failed"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment