Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Load the driver for the connection to MySQL
- String DRIVER = "com.mysql.jdbc.Driver";
- try {
- Class.forName(DRIVER);
- } catch (ClassNotFoundException e) {
- System.err.println("Driver not found: " + e);
- }
- // Connection to the MySQL database
- String URL_myDB = "jdbc:mysql://localhost:3306/database"; // Database URL
- String user = "root"; // Database user name
- String password = ""; // Database user password
- Connection connection = null;
- try {
- connection = DriverManager.getConnection(URL_myDB, user, password);
- } catch (Exception e) {
- System.err.println("Error while connecting to the database: " + e);
- }
- //CODE HERE
- // Close the connection
- try {
- connection.close();
- } catch (Exception e) {
- System.err.println("Error while closing the connection to the databse: " + e);
- }
Add Comment
Please, Sign In to add comment