`### Oracle
package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Test {
private static final String URL = "jdbc:oracle:thin:@//127.0.0.1:1521/orcl";
private static final String DRIVER = "oracle.jdbc.driver.OracleDriver";
private static final String USER = "SCOTT";
private static final String PASSWORD ="TIGER";
static{
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws SQLException {
Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
System.out.println(conn);
}
}
MySQL
package mysqljdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MysqlTest {
private static String URL="jdbc:mysql://localhost:3307/scott"+"?useSSL=false&useUnicode=true"+"&characterEncoding=UTF-8&serverTimezone=UTC";
private static String DRIVER="com.mysql.cj.jdbc.Driver";
private static String USER = "root";
private static String PASSWORD = "";
static{
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
System.out.println(conn);
}
}
|