这是我的功能:
private static void checkDatabase(String dbName, String password) {
try{
Connection con=DriverManager.getConnection(
"jdbc:sqlserver://localhost;database="+dbName+ ";user=SA;password=" +password);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("DBCC CHECKDB;");
while(rs.next()){
System.out.println( //TODO );
}
con.close();
}catch(Exception e){ System.out.println(e);}
}
我想使用 DBCC CHECKDB 检查所有数据库但收到此错误:
com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.
为什么 DBCC CHECK DB 不能与 executeQuery() 一起使用,我该如何解决?
因此,如果我已经从 stmt.executeQuery() 获得了 ResultSet,我如何将这个结果读取为行或字符串?我想看看有多少错误。谢谢你。