1. Oracle
package com.company.design.ioc;
import java.sql.*;
public class Main {
public static void main(String[] args) {
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String user = "root";
String password = "1234";
String sql = "";
Connection conn = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
Class.forName("oracle.jdbc.driver.OracleRiver");
conn = DriverManager.getConnection(url, user, password);
System.out.println("success");
sql = "selct * from board";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
}
2. mysql
package com.company.design.ioc;
import java.sql.*;
public class Main {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/TUTORIAL?useSSL=false&serverTimezone=UTC";
String user = "root";
String password = "1234";
String sql = "";
Connection conn = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection(url, user, password);
System.out.println("success");
sql = "selct * from board";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
}
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
}