Question

I am trying to execute a simple CREATE TABLE query on an oracle10g database using java. This is what I am doing:

Connection conn = //create connection
//open connection.  No errors/warnings are generated so I assume this succeeds 
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("CREATE TABLE t1 (c1 INTEGER NOT NULL, c2 VARCHAR(100), c3 INTEGER NULL, CONSTRAINT m_pk PRIMARY KEY (c1));");
...
//close connection.  No errors again so I assume it succeeds.

When I execute the command (copying and pasting into terminal window) directly on the command line, it succeeds. When I run the above java code, this is the error I get:

java.sql.SQLSyntaxErrorException: ORA-00911: invalid character

I dont understand how I could have an invalid character since copying and pasting it into terminal works perfectly fine. If I leave off the ";" at the end of the query everything runs without any errors but no table is created as expected. I have tried many variations of the above query and nothing seems to work. Just doing "CREATE TABLE t1;" does nothing and doing "CREATE TABLE t1 ( c1 INTEGER );" does nothing either.

Was it helpful?

Solution

Nevermind. I jumped the gun on posting here! When executing queries in java, I am not suppose to put the semi-colon at the end of the statement. I had tried not putting the semi-colon at the end and it ran without errors but I thought I had checked my database and saw that no table was created. I have now confirmed that dropping the semi-colon has worked!

OTHER TIPS

You don't need to add the semicolon at the end. Can you please try running the program without it being there?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top