Advertisement
Guest User

Untitled

a guest
Oct 14th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. public class DBConnect {
  2. private static Connection con = null;
  3. public static Connection createCon(){
  4. if(con!=null)
  5. return con;
  6. try {
  7. Class.forName("com.mysql.jdbc.Driver");
  8. } catch (ClassNotFoundException e) {
  9. // TODO Auto-generated catch block
  10. e.printStackTrace();
  11. System.out.println("Exception occurred while loading com.mysql.jdbc.Driver ClassNotFoundException");
  12. }
  13.  
  14. try {
  15. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","xxx","xxx");
  16. } catch (SQLException e) {
  17. e.printStackTrace();
  18. System.out.println("Connection establishment failed SQLException");
  19. }
  20. return con;
  21. }
  22. static void closeCon(){
  23. try {
  24. if(con!=null)
  25. con.close();
  26. } catch (SQLException e) {
  27. e.printStackTrace();
  28. System.out.println("Connection shutdown failed SQLException");
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement