java.sql.SQLException:ORA-00928:缺少SELECT关键字。使用JDBC将记录插入DB时 [英] java.sql.SQLException: ORA-00928: missing SELECT keyword. when inserting record to DB using JDBC

查看:822
本文介绍了java.sql.SQLException:ORA-00928:缺少SELECT关键字。使用JDBC将记录插入DB时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试向db插入一些行时出现错误。所以这里是代码

I get an error when I try to insert some rows to a db. so here is the code

try {
    String insertStmt = "INSERT into " +
                        "MY_TABLE('RECORD_TYPE', 'FILE_TYPE', 'DATE', 'BATCH_NO', 'RECORD_COUNT')" +
                        "VALUES(?, ?, ?, ?, ?);";

    PreparedStatement pstmt = super.con.prepareStatement(insertStmt);

    pstmt.setString(1, input[0]);
    pstmt.setString(2, input[1]);
    pstmt.setString(3, input[2]);
    pstmt.setString(4, input[3]);
    pstmt.setString(5, input[4]);

    System.out.println("Insert rows : " + pstmt.executeUpdate());

} catch (SQLException sqle) {
    System.out.println(sqle.getMessage());
    sqle.printStackTrace();
} catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
} finally {
    con.close();
}

并且db上的所有内容都是varchar类型,双重检查列(它们是所有都是同一个名字),从列名中取出引号(同样的结果)没有成功。要添加它,错误消息不是很有帮助。

and everything on the db is of varchar type, double checked the columns (they all are the same name), took out the quotes off the column name (same result) no success. to add it up, the error message is not very helpful.

任何建议都将受到赞赏。

any suggestions would be appreciated.

推荐答案

我可以发现两个问题:


  1. 不需要在列名周围加单引号。但你可以用双引号括起来。如果要对列名或表名使用保留关键字,则必须执行此操作。这里 DATE

  2. 你需要一个空格 VALUES

  1. No need for single quotes around column names. But you may wrap it in double quotes. It is necessary if you are using reserved keywords for column names or table names. Here DATE.
  2. You need a space before VALUES.

因此您需要将 insertStmt 更改为以下内容:

So you need to change insertStmt to somthing like this:

String insertStmt = "INSERT into " +
    "MY_TABLE(RECORD_TYPE, FILE_TYPE, \"DATE\", BATCH_NO, RECORD_COUNT) " +
    "VALUES(?, ?, ?, ?, ?);";

这篇关于java.sql.SQLException:ORA-00928:缺少SELECT关键字。使用JDBC将记录插入DB时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆