使用jdbc将查询插入数据库时出错

时间:2020-12-28 04:32:41

in my application I'm trying to insert a query into an oracle database using jdbc. I create this table:

在我的应用程序中,我尝试使用jdbc将查询插入到oracle数据库中。我创建这个表:

create table TMP
(
SYNC       NUMBER,
USER       VARCHAR2(50),
DAT       DATE
)

And I use this code to insert an entry:

我用这个代码插入一个条目:

PreparedStatement stat=null;

    try {
        dbStatement = dbConnection.createStatement();

        String sql = "INSERT INTO TMP (USER, DAT) Values (?,?);";

        for (ReplicationHistoryDetailVO tmpEntry : entry) {
            if (tmpEntry.getSyncPhase() == REPLICATION_PHASE.DOWNLOAD) {
                stat=dbConnection.prepareStatement(sql);
                stat.setString(1, "David");
                stat.setDate(2, new Date(tmpEntry.getFinishTime()));
                stat.executeUpdate();               
            }
        }

From this code I have the following error:

从这段代码中,我有以下错误:

Error updating database java.sql.SQLSyntaxErrorException: ORA-00911

The connection is ok. I must to write only two values, because the first value is an autoincremental key and I don't set this. Any ideas?

连接好。我必须只写两个值,因为第一个值是自动递增键,我没有设置这个。什么好主意吗?

1 个解决方案

#1


2  

Try "INSERT INTO TMP (USER, DAT) Values (?,?)" without the ; at the end.

尝试“插入到TMP (USER, DAT)值(?,?)”,而不使用;在最后。

ORA-00911 is a common error for common syntax mistakes.  

#1


2  

Try "INSERT INTO TMP (USER, DAT) Values (?,?)" without the ; at the end.

尝试“插入到TMP (USER, DAT)值(?,?)”,而不使用;在最后。

ORA-00911 is a common error for common syntax mistakes.