Advertisement
Guest User

Untitled

a guest
Apr 5th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Properties;
  3.  
  4. public class DBDemo
  5. {
  6. // The JDBC Connector Class.
  7. private static final String dbClassName = "com.mysql.jdbc.Driver";
  8.  
  9. private static final String CONNECTION =
  10. "jdbc:mysql://127.0.0.1/deathquest";
  11.  
  12. public static void main(String[] args) throws
  13. ClassNotFoundException,SQLException
  14. {
  15. System.out.println(dbClassName);
  16. // Class.forName(xxx) loads the jdbc classes and
  17. // creates a drivermanager class factory
  18. Class.forName(dbClassName);
  19.  
  20. // Properties for user and password. Here the user and password are both 'paulr'
  21. Properties p = new Properties();
  22. p.put("user","root");
  23. p.put("password","R1ggth20");
  24.  
  25. // Now try to connect
  26. Connection c = DriverManager.getConnection(CONNECTION,p);
  27.  
  28. System.out.println("It works !");
  29. c.close();
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement