11.15
深入学习了 MySQL 的复制功能在 Java 应用中的体现
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class JavaMySQLReplicationExample {
public static void main(String[] args) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://slave_host:3306/mydatabase", "username", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM some_table");
while (rs.next()) {
System.out.println(rs.getString("column_name"));
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}