Guest User

Untitled

a guest
May 17th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. // Load the driver for the connection to MySQL
  2. String DRIVER = "com.mysql.jdbc.Driver";
  3. try {
  4. Class.forName(DRIVER);
  5. } catch (ClassNotFoundException e) {
  6. System.err.println("Driver not found: " + e);
  7. }
  8.  
  9. // Connection to the MySQL database
  10. String URL_myDB = "jdbc:mysql://localhost:3306/database"; // Database URL
  11. String user = "root"; // Database user name
  12. String password = ""; // Database user password
  13. Connection connection = null;
  14. try {
  15. connection = DriverManager.getConnection(URL_myDB, user, password);
  16. } catch (Exception e) {
  17. System.err.println("Error while connecting to the database: " + e);
  18. }
  19.  
  20. //CODE HERE
  21.  
  22. // Close the connection
  23. try {
  24. connection.close();
  25. } catch (Exception e) {
  26. System.err.println("Error while closing the connection to the databse: " + e);
  27. }
Add Comment
Please, Sign In to add comment