简体   繁体   English

使用JDBC准备语句插入时出错

[英]Error while inserting using JDBC prepared statement

I am trying to insert some values into Oracle DB from Java using the following JDBC statement: 我正在尝试使用以下JDBC语句从Java将一些值插入Oracle DB:

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? 有什么问题?

Possibly looking at the wrong table or database. 可能查看了错误的表或数据库。 Are you sure your looking at the right database from the code? 您确定从代码中查找正确的数据库吗?

In prepare statement no need to give schema name(In this case ABC). 在prepare语句中,无需提供架构名称(在这种情况下为ABC)。

Try this, it might work. 试试这个,可能会起作用。

String SQL_PREP_INSERT = "INSERT INTO TEST (LOG_ID, SESSION_ID,USER_ID) VALUES" + " (logid_seq.nextval, ?, ?)"; 字符串SQL_PREP_INSERT =“插入测试(LOG_ID,SESSION_ID,USER_ID)VALUES” +“(logid_seq.nextval,?,?)”;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM