Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Connection from DataSource only allows "selects"!

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

I'm doing some jdbc code in a Faces app. I get a DataSource from the appserver then a connection from this. I can run 'select' queries but all insert,update and delete fail silently. They appear to have run, the execute method returns fine and no exceptions are thrown but the db is not updated.

This is extremely confusing...I know the connection is working-ish because I can do selects. I'm connecting to Oracle 9i. This is my code:


pllllleeassseee, any ideas?
thanks,
john
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume you mean that you are executing this:



And what is the value of the boolean variable returned?

Please post your code which updates the DB.
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. check the auto-commit mode of connection
2. if you are managing transactions by any means like ejb,jta make sure you are commiting your transaction

it is adivised that if you are not having transaction via ejb,or jta the set auto-commit mode of connection to false immediate after you create connection

and use conn.commit() after you execute an insert statement or update statement

Shailesh
 
author & internet detective
Posts: 40801
829
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John,
Also check that the id you are using to access the database has write permission.
 
John Summers
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for your replies.

In response to a suggestion on the Sun Creator forum I changed my code to:


but the problem still persists. The id to log into the database is correct.
When I change my getConnection method to use an ordinary connection i.e.
DriverManager.getConnection...

the sql works fine.

john
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure but it seems that you are not commiting transaction.
and when you get connection from datamanager then your auto-commit mode is true.

could you answer to my previous query also paste the complete code here.

Shailesh
 
John Summers
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Here's my code:


I wasn't aware I had to do connection.commit when autocommit was set to true. Surely the line "boolean results = statement.execute" runs the sql?

john
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your statement executing well with your DB client? Where is the query?
 
reply
    Bookmark Topic Watch Topic
  • New Topic