Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cat.insvidreres.mysqlconnection;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class MySQLConnection {
- public static void main(String[] args) {
- Connection conn = null;
- try {
- // db parameters
- String url = "jdbc:mysql://192.168.19.134:3306/hr";
- String user = "root";
- String password = "Admin123";
- // create a connection to the database
- conn = DriverManager.getConnection(url, user, password);
- // processing here
- } catch(SQLException e) {
- System.out.println(e.getMessage());
- } finally {
- try{
- if(conn != null)
- conn.close();
- }catch(SQLException ex){
- System.out.println(ex.getMessage());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment