Guest User

Untitled

a guest
Jul 17th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 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. // Connection string. emotherearth is the database the program
  10. // is connecting to. You can include user and password after this
  11. // by adding (say) ?user=paulr&password=paulr. Not recommended!
  12.  
  13. private static final String CONNECTION =
  14. "jdbc:mysql://127.0.0.1/ZAJEMix";
  15.  
  16. public static void main(String[] args) throws
  17. ClassNotFoundException,SQLException
  18. {
  19. System.out.println(dbClassName);
  20. // Class.forName(xxx) loads the jdbc classes and
  21. // creates a drivermanager class factory
  22. Class.forName(dbClassName);
  23.  
  24. // Properties for user and password. Here the user and password are both 'paulr'
  25. Properties p = new Properties();
  26. p.put("user","root");
  27. p.put("password","abcd1234");
  28.  
  29. // Now try to connect
  30. Connection c = DriverManager.getConnection(CONNECTION,p);
  31.  
  32. System.out.println("It works !");
  33. c.close();
  34. }
  35. }
Add Comment
Please, Sign In to add comment