Java 能不能执行mysql 中的show master status 命令
1个回答
展开全部
详细参考文章:http://www.yuanxingyuan.com/?id=18
可以的,使用Statement 的 executeQuery,示例代码:
public static List<String> getDBMasterStatus() {
List<String> status = new ArrayList<String>();
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://127.0.0.1:3306/sshdb";
try {
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, "root", "123456");
Statement stm = conn.createStatement();
ResultSet rs = stm.executeQuery("show master status");
while(rs.next()) {
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getString(4));
}
rs.close();
stm.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return status;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询