简体   繁体   中英

org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement

I'm working in java with h2 as the in-memory database but it keeps telling me that I have a syntax error and I can't find what it is


import java.sql.*;

public class Test {

    private static final String SQL_CREATE_TABLE = "DROP TABLE IF EXISTS CUENTAS; CREATE TABLE CUENTAS "
            + "("
            + " ID INT PRIMARY KEY, "
            + " NOMBRE varchar(100) NOT NULL"
            + " NUMERO_CUENTA NUMERIC(10, 2) NOT NULL, "
            + " SALDO FLOAT NOT NULL"
            + ")";

    private static final String SQL_INSERT = "INSERT INTO CUENTAS (ID, NOMBRE, NUMERO_CUENTA, SALDO) VALUES(?, ?, ?, ?)";
    private static final String SQL_UPDATE = "UPDATE CUENTAS SET SALDO=? WHERE ID=?";
    

You seem to be missing a comma after the NOMBRE field


import java.sql.*;

public class Test {

    private static final String SQL_CREATE_TABLE = "DROP TABLE IF EXISTS CUENTAS; CREATE TABLE CUENTAS "
            + "("
            + " ID INT PRIMARY KEY, "
            + " NOMBRE varchar(100) NOT NULL," //<-- comma missing here
            + " NUMERO_CUENTA NUMERIC(10, 2) NOT NULL, "
            + " SALDO FLOAT NOT NULL"
            + ")";

    private static final String SQL_INSERT = "INSERT INTO CUENTAS (ID, NOMBRE, NUMERO_CUENTA, SALDO) VALUES(?, ?, ?, ?)";
    private static final String SQL_UPDATE = "UPDATE CUENTAS SET SALDO=? WHERE ID=?";

Let me know if this works for you.

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