无法使用 Java (JDBC) 在 Oracle 中插入一行 --> 错误 ORA-00917:缺少逗号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5497069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:11:45  来源:igfitidea点击:

Unable to insert a row in Oracle with Java (JDBC) --> error ORA-00917: missing comma

javaoraclejdbcora-00917

提问by Noob

I have a problem during an insert in Oracle using Java and JDBC. The error obtained is:

我在使用 Java 和 JDBC 在 Oracle 中插入时遇到问题。得到的错误是:

java.sql.SQLException: ORA-00917: missing comma

java.sql.SQLException: ORA-00917: 缺少逗号

The data for the insert is taken from a form like a string and is parsed to the appropiated data type and then is saved in an object called edicio. That's all OK. Then, my intention is make an insert in the DB using the data of this object.

用于插入的数据取自类似字符串的形式,并被解析为合适的数据类型,然后保存在名为 edicio 的对象中。没关系。然后,我的目的是使用这个对象的数据在数据库中插入。

Here is the code of the DAO, where I'm making the insert:

这是 DAO 的代码,我在其中进行插入:

public Edicio insertarCurs(Connection con, Edicio ed) throws SQLException {
    PreparedStatement stm = null;
    ResultSet rst = null;

    // Insert
    StringBuffer sql = new StringBuffer();
    sql.append("INSERT INTO curs (id, nom, idarea, area, programa, datainici)");
    sql.append(" VALUES (?, ?, ?, ?, ?, ?");
    logger.info("Building insert works fine.");

    try {
        stm = con.prepareStatement(sql.toString());
        // params
        stm.setLong(1, ed.getIdEdicio());
        stm.setString(2, ed.getNomEdicio());
        stm.setLong(3, ed.getIdArea());
        stm.setString(4, ed.getArea());
        stm.setString(5, ed.getPrograma());
        // Conversion from Java Date to SQL Date
        java.sql.Date sqlDate = new java.sql.Date(ed.getDataInici().getTime());
        logger.info("sqlDate before the insert is: "+ sqlDate); //0011-12-02
        stm.setDate(6, sqlDate);

                // Data and results commented
        logger.info("Id edicio: "+ ed.getIdEdicio()); //6
        logger.info("Nom edicio: "+ ed.getNomEdicio()); //test
        logger.info("Id area: "+ ed.getIdArea()); //0
        logger.info("Nom area: "+ ed.getArea()); //test
        logger.info("Programa: "+ ed.getPrograma()); //test
        logger.info("Data inici: "+ sqlDate); //2011-06-06

        // We are going to execute the insert
        int numRows = stm.executeUpdate();
        // The program never reaches this point, fails doing the executeUpdate()
                logger.info("Rows created: "+ numFiles);
                ...

The variable types are:

变量类型是:

idEdicio = long  
nomEdicio = String  
idArea = long  
area = String  
programa = String  
dataInici = Date  

Can someone help me? Thank you in advance :)

有人能帮我吗?先感谢您 :)

回答by Adrian Pronk

Missing )

丢失的 )

sql.append(" VALUES (?, ?, ?, ?, ?, ?");

should be

应该

sql.append(" VALUES (?, ?, ?, ?, ?, ?)");

回答by JB Nizet

sql.append(" VALUES (?, ?, ?, ?, ?, ?)");
                                     ^--- missing parenthesis