Skip to content

Instantly share code, notes, and snippets.

@1ik
Created August 13, 2013 04:43
Show Gist options
  • Save 1ik/6217962 to your computer and use it in GitHub Desktop.
Save 1ik/6217962 to your computer and use it in GitHub Desktop.
JDBC Connector class for java
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