Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DBConnect {
- private static Connection conn;
- private static String url = "jdbc:mysql://localhost/company";
- private static String user = "root";
- private static String pass = "root";
- public Connection connect() throws SQLException{
- try{
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- }catch(ClassNotFoundException cnfe){
- System.err.println("Erreur: "+cnfe.getMessage());
- }catch(InstantiationException ie){
- System.err.println("Erreur: "+ie.getMessage());
- }catch(IllegalAccessException iae){
- System.err.println("Erreur: "+iae.getMessage());
- }
- conn = DriverManager.getConnection(url,user,pass);
- return conn;
- }
- public Connection getConnection() throws SQLException, ClassNotFoundException{
- if(conn !=null && !conn.isClosed())
- return conn;
- connect();
- return conn;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement