如何使用java代码截断表
try{
con=db.setConnetion();
stm=con.createStatement();
stm.executeUpdate("TRUNCATE TABLE temptblDateWiseReport");
System.out.println("Truncated");
stm.close();
con.close();
}catch(SQLException ex){
System.out.println("General Info Error");
ex.printStackTrace();
}
它给出了错误
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3109)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:337)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:287)
at com.AshaIndustry.gui.DateWiseReport.jbtnPrintActionPerformed(DateWiseReport.java:245)
答案 0 :(得分:6)
AFAIK MS Access不支持TRUNCATE关键字。您可以使用:
delete from temptblDateWiseReport