【发布时间】:2016-10-25 09:23:48
【问题描述】:
当我按照代码运行时,出现以下错误。
public Consent insert(Consent c) {
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(
"INSERT INTO KIT.CONSENT (tr_number, customer, id_data, user, fk_user) "
+ "VALUES (?, ?, ?, ?, ?)",
new String[] { "ID" });
ps.setString(1, c.getTr_number());
ps.setString(2, c.getCustomer());
ps.setString(3, c.getId_data());
ps.setString(4, c.getUser());
ps.setInt(5, c.getFk_user());
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();
while(rs.next()){
int id = rs.getInt(1);
c.setId(id);
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
错误:
原因:java.sql.SQLSyntaxErrorException: ORA-01747: 无效的 user.table.column、table.column 或列规范
此代码适用于 MySQL,但在 Oracle 中会引发以下错误
【问题讨论】:
-
我认为,该用户是 Oracle 中的保留字,不应用作列名
-
是的,伙计。因为用户是Oracle中的保留字。问题已解决,谢谢。