2
votes

When I am running following Code I am getting following error.

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);
    }

Error:

Caused by: java.sql.SQLSyntaxErrorException: ORA-01747: invalid user.table.column, table.column, or column specification

This code works on MySQL but in Oracle throws following error

1
I think, that user is reserved word in Oracle and should not be used for column name - Mottor
Yes man. because of user is reserved word in Oracle. Problem is solved thanks. - Musa

1 Answers

2
votes

ORA-01747 - You are using a reserved word as column name. If you try to create table with column name user you will get an error. You have created the table with column name "user" which is different of user and now when you do insert you should use "user" as column name.

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

It is not recommended to use reserved words as column names