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

Marvin Effing picture Marvin Effing · Oct 24, 2012 · Viewed 9.3k times · Source

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.

Answer

John Woo picture John Woo · Oct 24, 2012

remove (,2) in the double data type.

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

See Demonstration