• 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:

commit problem - always happens even if set to false!!

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I have a problem doing the following:
1-get a connection object
2-set its auto commit to false
3-get a PreparedStatement from the Connection object
4-last I call ps.executeUpdate();

I DO NOT call commit() on my Connection object, so I expect the program not to do any insert/updates, but... surprise! it does
my PreparedStatement obj writes to the db...

Can anyone tell me how this can be??

Thanks a lot
[ September 13, 2004: Message edited by: Lukas Alamar ]
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you rolling the transaction back? If not, I believe that the connection object may be performing a commit when it closes if it detects an open transaction. Perhaps someone more in the know on this issue could comment?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What database are you using? All of the databases that I have used with the exception of Oracle auto commit. I would suggest forcing a roll back if you do not want to commit.
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I very much doubt that you'd be seeing the behaviour that Bear suggests. The natural thing to do (if anything - I would suggest nothing) would be for the driver software to rollback under those circumstances.

The more likely explanation is that the database you're using (my guess would be the ubiquitous MySQL) doesn't support transactions by default (or in your version). I take it you're sure that the data is committed and that you aren't just looking at uncommitted data somehow (possible either within the same session/connection or using READ_UNCOMMITTED transaction isolation)?

All major RDBMS (Oracle, Sybase, MS SQL Server, DB2, Ingres) support transactions by default in my experience. It's only noddy ones like Access and MySQL that don't.

Hope that helps.

Jules
 
Lukas Alamar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, thanks for your reply, I got it fixed with con.rollback().

By the way :roll: ,
have you ever had problems using a PreparedStatement object's setNull()??
I do the following

and get this error:
java.sql.SQLException: Could not execute sql command - Original message: null

If I try to execute the same query on my db client...it works.

I have to set that value to null and the corresponding db field is of type CHAR and is nullable.

Maybe some of you had the same problem and can help.

Thanks.
[ September 16, 2004: Message edited by: Lukas Alamar ]
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Try giving java.sql.NULL i.e.,

ps.setNull(1, java.sql.NULL);
 
Jyothi Lature
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, i meant java.sql.Types.NULL
 
Lukas Alamar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no way... it still doesnt work...


i cant figure it out...

any ideas??
 
Lukas Alamar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been trying everything:

ps.setString(10, null);
ps.setNull(10, Types.CHAR);
ps.setString(10, Types.NULL);

I'always getting
java.sql.SQLException: Could not execute sql command - Original message: null
on this line:

ps.executeUpdate();

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the sql you are trying to do an update for? Print that out. The error may not be related to the parameter settings.
 
Lukas Alamar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I do print it out and execute it, it works fine this way, it just doesn't work at runtime.
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try using ps.setString(10, "") instead
thnks
 
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic