• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Prepared statements ?

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Pl. give your tips...

The above code work well by inserting data to the PSTData table, but when i use a PreparedStatement to do the insert. It doesn't work, it gives SQLException.

Why? Is it wrong to use a PreparedStatement for a insert query?

Thanks in advance,
-
vanchin
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Can you post your code?
 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

here follows the code:


This gives me an SQL exception...

thanks
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and what's the SQLException?
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're not using the prepared statement correctly.
The statement should not be:
"INSERT into PSTData values ?"
it should be:
"INSERT into PSTData values (?, ?, ?, ?, ?)"
 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lu & Paul, Thanks for the syntax, my prepared statement was wrong...

got it done...
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a tip, if your code goes that way, you may try using the addBatch method of the prepared statement. Your code will have a great impact on your network, since you will send sql statement back and forth from your server everytime your loop is executed.

At the end of your loop, you may issue the execute() statement to execute your sql statements once.
 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Arnel,

Sorry, I am not quite sure of batch methods. Can you guide me to some resource materials that shows how to...

thanks
 
arnel nicolas
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vanchi,

Your code as modified using addBatch() method.



Thats quite easy isn't it.


Happy coding...
[ July 14, 2004: Message edited by: arnel nicolas ]
 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Arnel,

This means that all the N-number of queries of the same type are sent to the database server at the same time to get executed. Hence the connect to the DB server is done only one time.

Is there any limitations to the batch processing?

thanks in advance...
 
reply
    Bookmark Topic Watch Topic
  • New Topic