【问题标题】:Caused by: java.sql.SQLSyntaxErrorException: ORA-01747: invalid user.table.column, table.column, or column specification引起:java.sql.SQLSyntaxErrorException:ORA-01747:无效的 user.table.column、table.column 或列规范
【发布时间】: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中的保留字。问题已解决,谢谢。

标签: mysql oracle


【解决方案1】:

ORA-01747 - 您正在使用保留字作为列名。如果您尝试使用列名 user 创建表,您将收到错误消息。您已经创建了列名为“user”的表,这与用户不同,现在当您插入时,您应该使用“user”作为列名。

INSERT INTO KIT.CONSENT (tr_number, customer, id_data, "user", fk_user) 

不建议使用保留字作为列名

【讨论】:

    猜你喜欢
    • 2012-03-16
    • 2013-10-21
    • 2018-12-19
    • 2013-04-28
    • 2015-05-01
    • 1970-01-01
    • 2021-03-05
    • 2012-01-21
    • 1970-01-01
    相关资源
    最近更新 更多