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 preparestatment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "preparestatment" Watch "preparestatment" New topic
Author

preparestatment

anvi kon
Ranch Hand

Joined: Jan 08, 2010
Posts: 133
Hi,

I am doing like below.


It is not working. I am not getting the del cnt. It is throwing an exception.


Can anyone tell me what is wrong in the above code?

Thanks


Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

anvi kon wrote:Hi,... It is throwing an exception...
What does that exception say?


OCUP UML fundamental and ITIL foundation
youtube channel
anvi kon
Ranch Hand

Joined: Jan 08, 2010
Posts: 133
Hi,

Exception says: you cannot rollback with autocommit set.


My question , Is the below code returns the int or not?




Thanks

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30356
    
150

It returns the int on success.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
YogeshS Pandit
Greenhorn

Joined: May 10, 2010
Posts: 9
Yes, it returns int for INSERT,UPDATE,DELETE statements and 0 for DDL statements. Check out this link..
lokesh pattajoshi
Ranch Hand

Joined: Jul 29, 2009
Posts: 130
Once Check you have delete permission or not..
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
There's something confused in your instruction.

You get the PreparedStatement from the connection with the method



and you pass to this method the sql query String

Then you invoke the super interface (Statement) version of executeUpdate with another sql query.

If the query is



then don't even use a PreparedStatement, but just a Statement



Bye,
Nicola
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30356
    
150

Nicola Garofalo wrote:There's something confused in your instruction.

You get the PreparedStatement from the connection with the method



and you pass to this method the sql query String

Then you invoke the super interface (Statement) version of executeUpdate with another sql query

Good catch!
 
Consider Paul's rocket mass heater.
 
subject: preparestatment