Search code examples
javasqlprepared-statementsqlexception

java.sql.SQLSyntaxErrorException: Syntax error: Encountered "(" at line


I'm executing the following:

private void createTable() {
    try {       
        PreparedStatement psCreateTable = con.prepareStatement("CREATE TABLE     COMPANIES(" +
                "name VARCHAR(50), " +
                "location VARCHAR(50), " +
                "address VARCHAR(50), " +
                "website VARCHAR(50), " +
                "pit VARCHAR(50), " +
                "asset_class VARCHAR(50), " +
                "telephone INTEGER, " +
                "shares INTEGER, " +
                "value DOUBLE(,2) UNSIGNED)");
        psCreateTable.execute();
    } catch (SQLException e) {
        System.out.println("already exists");
        e.printStackTrace();
        ; //bestaat al
    }
}

And I get the following error: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "(" at line 1, column 195.

Not really sure what to do now, as the SQL query seems valid to me and rechecked it.


Solution

  • remove (,2) in the double data type.

    CREATE Table Companies
    (
        ....,
        value DOUBLE UNSIGNED
    )
    

    See Demonstration