Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DBConnect {
- private static Connection con = null;
- public static Connection createCon(){
- if(con!=null)
- return con;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- System.out.println("Exception occurred while loading com.mysql.jdbc.Driver ClassNotFoundException");
- }
- try {
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","xxx","xxx");
- } catch (SQLException e) {
- e.printStackTrace();
- System.out.println("Connection establishment failed SQLException");
- }
- return con;
- }
- static void closeCon(){
- try {
- if(con!=null)
- con.close();
- } catch (SQLException e) {
- e.printStackTrace();
- System.out.println("Connection shutdown failed SQLException");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement