Gopi
Gopi

Reputation: 237

Error while inserting using JDBC prepared statement

I am trying to insert some values into Oracle DB from Java using the following JDBC statement:

String SQL_PREP_INSERT = "INSERT INTO ABC.TEST (LOG_ID, SESSION_ID,USER_ID) VALUES"
            + " (ABC.logid_seq.nextval, ?, ?)";

stmt = con.prepareStatement(SQL_PREP_INSERT);
stmt.setString(1, sessionId);
stmt.setString(2, userid);
stmt.execute();
stmt.close();

The sequence is created as follows:

create sequence  ABC.logid_seq
minvalue 1 maxvalue 9999999999999999999999 
increment by 10 start with 10 cache 20 noorder  nocycle ;

I am getting the following error,

java.sql.SQLException: ORA-00942: table or view does not exist

But when I try to insert into the table manually, it's successful.

insert into ABC.test(LOG_ID,SESSION_ID,USER_ID) values 
    (VZPPTL.logid_seq.nextval,'test_session', '001');

What's the problem?

Upvotes: 0

Views: 1578

Answers (2)

Sathish Santhosam
Sathish Santhosam

Reputation: 185

In prepare statement no need to give schema name(In this case ABC).

Try this, it might work.

String SQL_PREP_INSERT = "INSERT INTO TEST (LOG_ID, SESSION_ID,USER_ID) VALUES" + " (logid_seq.nextval, ?, ?)";

Upvotes: 1

seeker
seeker

Reputation: 6991

Possibly looking at the wrong table or database. Are you sure your looking at the right database from the code?

Upvotes: 2

Related Questions