我使用ActiveJDBC和Oracle 11g DB。当我使用saveIt时,我得到java.sql.Exception。当我得到它的实例或列表时,一切都好。 我做错了什么?
Exception in thread "main" org.javalite.activejdbc.DBException: java.sql.SQLException: Invalid argument
зове, query: INSERT INTO dept (DEPTNO, DNAME, LOC) VALUES (?, ?, ?), params: 45, sdfa, fdg
at oracle.jdbc.driver.AutoKeyInfo.getNewSql(AutoKeyInfo.java:187)
at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:5704)
at org.javalite.activejdbc.DB.execInsert(DB.java:598)
at org.javalite.activejdbc.Model.insert(Model.java:2698)
at org.javalite.activejdbc.Model.save(Model.java:2597)
at org.javalite.activejdbc.Model.saveIt(Model.java:2524)
at JavaHomeTask.Dept.addPersistence(Dept.java:72)
at JavaHomeTask.App.addRow(App.java:103)
at JavaHomeTask.App.main(App.java:50)
Caused by: java.sql.SQLException: Invalid argument
... 9 more
这是我的代码:
public void addPersistence() throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Dept d = new Dept();
String value;
for (String s : getAttributesNames()) {
System.out.println("Enter " + s + " and press Enter button:");
value = reader.readLine();
d.set(s, value);
}
d.saveIt();
}
public List<String> getAttributesNames() {
return Arrays.asList("DEPTNO", "DNAME", "LOC");
}
答案 0 :(得分:2)
问题的原因是ActiveJDBC使用id列作为表中的Primari Key来识别应该使用哪个操作 - INSERT或UPDATE。如果表没有这样的列,程序员应该使用@IdName(“nameOfColumn”)注释手动指定PK。您可以找到更多信息here