This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

oracle query

 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oracle allows to pass DEFAULT as column value in the query To quote from oracle website

For e.g.

If the departments table had been created with a default value of 121 for the manager_id column, then you could issue the same statement as follows:



I want to write a single query using Prepared statement in JDBC which works for both default and non default case.



For non default mangers I will use the

For default manager what should I pass. Any idea ?


 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33696
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, you can't. Why not just use two queries in JDBC?
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Actually the queries are auto generated by a tool.
 
Lukas Eder
Ranch Hand
Posts: 48
5
Java Oracle Postgres Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot bind the DEFAULT SQL keyword to a JDBC bind variable. You could, however, solve this transparently using a trigger as such:



The above assumes that manager_id is a nullable column. If the column is NOT NULL, then you might be more lucky replacing the original INSERT through an INSTEAD OF trigger
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks but triggers are not allowed in the application.
 
Lukas Eder
Ranch Hand
Posts: 48
5
Java Oracle Postgres Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradeep bhatt wrote:Thanks but triggers are not allowed in the application.


Then you cannot do it with a single statement. You'll have to resort to two statements. One with a bind value, and another with the DEFAULT keyword.
 
Martin Vajsar
Sheriff
Pie
Posts: 3747
62
Chrome Netbeans IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another possibility would be to supply the default values directly from the Java side. Oracle database can be queried for default values of columns, see eg. here.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic