Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. try {
  2. Statement stmt;
  3.  
  4. //Register the JDBC driver for MySQL.
  5. Class.forName("com.mysql.jdbc.Driver");
  6.  
  7. //Define URL of database server for
  8. // database named mysql on the localhost
  9. // with the default port number 3306.
  10. String url =
  11. "jdbc:mysql://localhost:3306/mysql";
  12.  
  13. //Get a connection to the database for a
  14. // user named root with a blank password.
  15. // This user is the default administrator
  16. // having full privileges to do anything.
  17. Connection con =
  18. DriverManager.getConnection(
  19. url,"root", "samurai87");
  20.  
  21. //Display URL and connection information
  22. System.out.println("URL: " + url);
  23. System.out.println("Connection: " + con);
  24.  
  25. //Get a Statement object
  26. stmt = con.createStatement();
  27.  
  28. // stmt.executeUpdate(
  29.  
  30. con.close();
  31. }catch( Exception e ) {
  32. e.printStackTrace();
  33. }//end catch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement