使用java代码截断表

时间:2013-04-02 17:53:26

标签: java ms-access

如何使用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)

1 个答案:

答案 0 :(得分:6)

AFAIK MS Access不支持TRUNCATE关键字。您可以使用:

delete from temptblDateWiseReport