String SQL_ADD_ = "INSERT INTO DEPARTMENT VALUES ( Null, 'HR')";
或者
String SQL_ADD_ = "INSERT INTO DEPARTMENT VALUES ( '0', 'HR')"; stmt.executeUpdate(SQL_ADD_);

解决方案 »

  1.   

    不行
    如果用INSERT INTO DEPARTMENT VALUES ( Null, 'HR')",报错
    java.sql.SQLException: General error: Column 'DEPT_ID' cannot be null
    at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)
    at com.mysql.jdbc.MysqlIO.sqlQuery(Unknown Source)
    at com.mysql.jdbc.Connection.execSQL(Unknown Source)
    at com.mysql.jdbc.Connection.execSQL(Unknown Source)
    at com.mysql.jdbc.Statement.executeUpdate(Unknown Source)
    at com.mysql.jdbc.jdbc2.Statement.executeUpdate(Unknown Source)
    at AddTester.main(AddTester.java:24)
      

  2.   

    如果用INSERT INTO DEPARTMENT VALUES ( ‘0’, 'HR')",报错
    java.sql.SQLException: Invalid argument value: Duplicate entry '0' for key 1
    at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)
    at com.mysql.jdbc.MysqlIO.sqlQuery(Unknown Source)
    at com.mysql.jdbc.Connection.execSQL(Unknown Source)
    at com.mysql.jdbc.Connection.execSQL(Unknown Source)
    at com.mysql.jdbc.Statement.executeUpdate(Unknown Source)
    at com.mysql.jdbc.jdbc2.Statement.executeUpdate(Unknown Source)
    at AddTester.main(AddTester.java:24)
      

  3.   

    Duplicate entry '0' for key 1
    ???再试试这个
    INSERT INTO `DEPARTMENT` SET dept_name = 'HR';如果还不行,
    用    SHOW CREATE TABLE `DEPARTMENT`
    将表结构显示出来看看呢,