MySQL
1
2
3
4
5
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test?characterEncoding=UTF8";
Connection connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
Result result = stmt.executeUpdate(sql);
SQLServer
1
2
3
4
5
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:microsoft.sqlserver://localhost:1433/test";
Connection connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
Result result = stmt.executeUpdate(sql);
Oracle
1
2
3
4
5
6
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@localhost:1521:test";
Connection connection = DriverManager.getConnection(url, username, password);
PreparedStatement pstmt = connection.prepareStatement(sql);
pstmt.setString("param");
Result result = pstmt.executeUpdate();