Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Properties;
  3. public class DBDemo
  4. {
  5. // The JDBC Connector Class.
  6. private static final String dbClassName = "org.mariadb.jdbc.Driver";
  7. // Connection string. emotherearth is the database the program
  8. // is connecting to. You can include user and password after this
  9. // by adding (say) ?user=paulr&password=paulr. Not recommended!
  10. private static final String CONNECTION =
  11. "jdbc:mariadb://127.0.0.1/emotherearth";
  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. // Properties for user and password. Here the user and password are both 'paulr'
  20. Properties p = new Properties();
  21. p.put("user","root");
  22. p.put("password","Newton981");
  23. // Now try to connect
  24. Connection c = DriverManager.getConnection(CONNECTION,p);
  25. System.out.println("It works !");
  26. c.close();
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement