aspose file tools*
The moose likes JDBC and the fly likes oracle query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "oracle query" Watch "oracle query" New topic
Author

oracle query

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

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 ?



Groovy
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30752
    
156

As far as I know, you can't. Why not just use two queries in JDBC?


[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
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Thanks. Actually the queries are auto generated by a tool.
Lukas Eder
Ranch Hand

Joined: Jul 22, 2013
Posts: 41
    
    4

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


When Java and SQL work together, great software can evolve. That's why I have created jOOQ. Follow me on blog.jooq.org
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Thanks but triggers are not allowed in the application.
Lukas Eder
Ranch Hand

Joined: Jul 22, 2013
Posts: 41
    
    4

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

Joined: Aug 22, 2010
Posts: 3610
    
  60

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

Joined: Feb 27, 2002
Posts: 8919

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: oracle query