简体   繁体   中英

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

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

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

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.

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

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 :)

Missing )

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

should be

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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