File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes insert query working in toad and giving error in jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "insert query working in toad and giving error in jdbc" Watch "insert query working in toad and giving error in jdbc" New topic
Author

insert query working in toad and giving error in jdbc

Prabhat Dhanrajgir
Greenhorn

Joined: Oct 19, 2004
Posts: 3
hi guys...

i am using an insert query which works fine when i run it on toad and shows one row inserted. But when i use the same query in my java code using jdbc,
the purpose fails and in the logs the error comes as "not enough values" that is a SQL exception.

I am not able to comprehend that a query that works fine on toad fails in jdbc.

The code which i use is as :

String insert_val2 = "insert into listing values (a huge array of values)";
DBPSaccess dbp2 = new DBPSaccess(insert_val2);
boolean y = dbp2.insert();
dbp2.close();

i have checked there is no problem in connection or statement object.

I need help quickly guys so please pour in your suggestions

Thanking in advance.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
your array length is not equals to your no. of columns in table "listing".
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Originally posted by Prabhat Dhanrajgir:
hi guys...

logs the error comes as "not enough values" that is a SQL exception.

String insert_val2 = "insert into listing values (a huge array of values)";
.


Try to print the Insert statement in console & run that statement in Toad.


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Prabhat Dhanrajgir
Greenhorn

Joined: Oct 19, 2004
Posts: 3
thanks adeel for the reply but that is not so as i am giving the exact query which is working in toad so the no. of values given is indeed equal to the no. of columns in the table.
Prabhat Dhanrajgir
Greenhorn

Joined: Oct 19, 2004
Posts: 3
thanks srini...

but i have tried that also. I printed the query on console and from there copied it back to the toad and it worked.

So the query works on toad, i copy it from there into my java code it flops, and from java code or console i copy it back on toad and it works again. This is kind of a thing that defies logic.

Can u think of any other remedies...

waiting for any more suggestions
prabhat.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
What you do is instead of using the array, directly format the insert query & try to insert ..
If it works then the problem is with the array length only..
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
I solved the same kind of problem now .. It happened to my collegue ..
What was happening is A big select query was built using different parameters & while running he got some exception but the same query executed in Toad.

The problem was after getting the records, one column is formatted using SimPleDateFormat class that gave an exception since that was caught in a try catch block in which the catch block had no exception handling statement , the error was not known ..

Check the stuffs like that ....
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: insert query working in toad and giving error in jdbc
 
Similar Threads
Unable to Insert these Chinese Character
SQL Error!!
how to display a SQL query ?
Oracle TO_DATE problem
parent key not found