Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. package com.JDD.SimpleCommandTest;
  2. import java.sql.*;
  3.  
  4. public class JDBCConnect {
  5. private static Connection conn = null;
  6. public static void main (String[] args)
  7. {
  8.  
  9. }
  10.  
  11. public static boolean connectDB(String[] args)
  12. {
  13.  
  14. try
  15. {
  16. String userName= "plugman";
  17. String password= "password";
  18. String url = "jdbc:mysql://localhost/plugintest";
  19. String driver = "com.mysql.jdbc.Driver";
  20. Class.forName(driver).newInstance();
  21. conn = DriverManager.getConnection(url,userName,password);
  22. System.out.println ("Database connection established");
  23. }
  24. catch(Exception e)
  25. {
  26. System.err.println("Cannot connect to database server");
  27. e.printStackTrace();
  28. }
  29.  
  30. }
  31. public static boolean disconnectDB()
  32. {
  33. if (conn != null)
  34. {
  35. try
  36. {
  37. conn.close();
  38. System.out.println("Database connection terminated");
  39. }
  40. catch(Exception e)
  41. {
  42. /* ignore close errors */
  43. }
  44. }
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement