Here is my Function:
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);}
}
I wanna use DBCC CHECKDB to check all Databases but got this Error:
com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.
Why DBCC CHECK DB can not work with executeQuery() and how can i fix it ?
So if i have already ResultSet from stmt.executeQuery(), how can i read this Result as Lines or String? I want to read how many Errors are there. Thank you.
Use Boolean rs = stmt.execute("DBCC CHECKDB;"); instead.
Some SQL statements don't return a resultset.