• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

insert query working in toad and giving error in jdbc

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your array length is not equals to your no. of columns in table "listing".
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Prabhat Dhanrajgir
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ....
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic