jdbc mysql connection string code example

Example 1: java connect to mysql

import java.sql.*;  
class MySqlConn{  
    public static void main(String args[]){  
        try{  
            Class.forName("com.mysql.cj.jdbc.Driver");  
            Connection conn = DriverManager.getConnection("jdbc:mysql://
            localhost:3306/databasename","username","password");  
            Statement stmt = conn.createStatement();  
            ResultSet rs = stmt.executeQuery("select * from emp");    
            con.close();  
        }catch(Exception ex){
            System.out.println(ex);
        }  
    }
}

Example 2: mysql jdbc connection url

jdbc:mysql://host1:33060/sakila

Example 3: jdbc sql connection string

db_url      = jdbc:microsoft:sqlserver://HOST:1433;DatabaseName=DATABASE
db_driver   = com.microsoft.jdbc.sqlserver.SQLServerDriver
db_username = USERNAME
db_password = PASSWORD

Tags:

Sql Example