• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prepared statements ?

 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • 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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Can you post your code?
 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

here follows the code:


This gives me an SQL exception...

thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and what's the SQLException?
 
Lu Battist
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Hi Lu & Paul, Thanks for the syntax, my prepared statement was wrong...

got it done...
 
arnel nicolas
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic