• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting ORA-00911: Invalid character exception while creating table.

 
Ranjeet Deshmukh
Ranch Hand
Posts: 35
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I'm trying to create a table. Whenever I run below method throws: java.sql.SQLSyntaxErrorException: ORA-00911: invalid character for "stmt.execute(str1);" line.
Below is my method:

can anyone please help me out??
Thanks,
Ranjeet
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
 
Ranjeet Deshmukh
Ranch Hand
Posts: 35
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:What is the String in abc?

Its Employee. I'm trying to create table with name Employee.
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Check the contents of your SQL string e.g. through your debugger or simply print it out.
2. Copy the output SQL string.
3. Open your SQL shell e.g. SQL*Plus or use SQL*Developer (which is a free and very powerful tool for working with Oracle).
4. Paste your SQL string into the SQL interpreter and execute it.
5. Modify the SQL in your interpreter until it works.
6. Put the working SQL into your Java code.

This should help you find the problem, and it gives you a method for finding any similar problems in future. In fact, you can avoid problems like this by skipping steps 1 and 2, and simply build and test your SQL in a SQL shell before you put it into Java. Use the right tool for the right job.
 
Ranjeet Deshmukh
Ranch Hand
Posts: 35
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chris webster wrote:1. Check the contents of your SQL string e.g. through your debugger or simply print it out.
2. Copy the output SQL string.
3. Open your SQL shell e.g. SQL*Plus or use SQL*Developer (which is a free and very powerful tool for working with Oracle).
4. Paste your SQL string into the SQL interpreter and execute it.
5. Modify the SQL in your interpreter until it works.
6. Put the working SQL into your Java code.

This should help you find the problem, and it gives you a method for finding any similar problems in future. In fact, you can avoid problems like this by skipping steps 1 and 2, and simply build and test your SQL in a SQL shell before you put it into Java. Use the right tool for the right job.


Hi Chris,

I tried to execute sql query from sqldeveloper by replacing abc with Employee and it worked fine. Table got created Successfuly. I don’t know why its not working from java.

Thanks,
Ranjeet
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranjeet Deshmukh wrote:
Hi Chris,

I tried to execute sql query from sqldeveloper by replacing abc with Employee and it worked fine. Table got created Successfuly. I don’t know why its not working from java.

Thanks,
Ranjeet

That's not what I suggested. Get the actual SQL your Java program is trying to execute i.e. str1 in your code, and print it out. Then copy that SQL string and test it in SQLDeveloper.
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niot sure if it will make any difference, but you could try removing the final ";" from your SQL string in the Java code:

"...KEY (id));";
 
Paul Clapham
Sheriff
Posts: 21565
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even printing the SQL string out might not help as there might be non-displayable characters in there somehow.

Ranjeet, am I correct that when you typed your SQL string into SQL Developer you typed



? I think it's quite likely that you unknowingly typed a correct SQL statement which you didn't notice was different from what your code generates. For example you may not have noticed that your code doesn't have any space between the table name and the "(" character. I don't know if that's a problem but it's the sort of problem you would miss by retyping the SQL in a slightly different form.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic