4

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.

3 Answers 3

1

remove (,2) in the double data type.

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

See Demonstration

Sign up to request clarification or add additional context in comments.

9 Comments

Ok, I tried that, but now I get the following error: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "UNSIGNED" at line 1, column 196.
Removed the 'UNSIGNED' parameter, seems to work, but now I get the following error: java.sql.SQLException: At least one parameter to the current statement is uninitialized.
@MarvinEffing but it's working on sql fiddle. did you click the link?
@MarvinEffing the code you posted above is the one you are using? why is hat it shows error message At least one parameter to the current statement is uninitialized.? do you have a parameterized query othjer than that?
Yeah ok works now, I always end up forgetting the tiniest things.
|
0

Your SQL query has an error: "value DOUBLE(,2) UNSIGNED)");

Change your PreparedStatement to something like this:

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 UNSIGNED)");

Comments

0
DOUBLE(,2)

This is wrong.

You may try

DOUBLE(5,2)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.