Question

can I use setObject() method of PreparedStatement for all datatypes(like string, int, double..) for Oracle database and in its OJDBC?

Possible duplicate is this :

setObject() method of PreparedStatement

But I want to know about using it for Oracle database and OJDBC. What are possible problems?

Was it helpful?

Solution

The possible problems are:

  1. You are delaying type validation till the application execution and don't take advantage of type safety. So you'll have errors during execution which could be easily caught at compilation time.
  2. You are loosing control of how types are inferred which might lead to weird formatting in some cases

My advise is to use setObject only if absolutely necessary.

OTHER TIPS

One problem that I came across is the ambiguity that arises in case of null values. In my application, this led to problems for the database to cache queries properly. To avoid this I had to check if the value was null and use #setNull(index, class) in these cases.

For non-null values I haven't come across any problems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top