jdbc - The statement did not return a result set. Java Error -
i trying delete data table java using jdbc. first counting no of rows , making sure table not empty , truncating data.
here code using
class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); connection con = drivermanager.getconnection("jdbc:sqlserver://m-i:1433;databasename=tes", "sa", "password"); statement cnnt= con.createstatement(); statement del1 = con.createstatement(); resultset rs = cnnt.executequery("select count(lea) cnt dbo.link"); int count= 0; if(rs.next()) { count = rs.getint("cnt"); } system.out.println(count); if(count != 0) { del1.executequery("truncate table dbo.link"); } else { system.out.println("table empty"); }
error:
exception in thread "main" com.microsoft.sqlserver.jdbc.sqlserverexception: statement did not return result set. @ com.microsoft.sqlserver.jdbc.sqlserverexception.makefromdrivererror(sqlserverexception.java:190) @ com.microsoft.sqlserver.jdbc.sqlserverstatement.doexecutestatement(sqlserverstatement.java:800) @ com.microsoft.sqlserver.jdbc.sqlserverstatement$stmtexeccmd.doexecute(sqlserverstatement.java:689) @ com.microsoft.sqlserver.jdbc.tdscommand.execute(iobuffer.java:5696) @ com.microsoft.sqlserver.jdbc.sqlserverconnection.executecommand(sqlserverconnection.java:1715) @ com.microsoft.sqlserver.jdbc.sqlserverstatement.executecommand(sqlserverstatement.java:180) @ com.microsoft.sqlserver.jdbc.sqlserverstatement.executestatement(sqlserverstatement.java:155) @ com.microsoft.sqlserver.jdbc.sqlserverstatement.executequery(sqlserverstatement.java:616)
the error @ truncate table dbo.link.
am doing right way?
can me please.
thanks.
don't use executequery
execute ddl statement; use executeupdate
.
to quote linked javadocs:
executes given sql statement, may insert, update, or delete statement or sql statement returns nothing, such sql ddl statement.
(emphasis mine)
and truncate table statement ddl statement.
Comments
Post a Comment