1

I have a program in which I bind the variables in a loop all using:

// Loop Start on i=1
preparedStatement.setObject(i , Val);
i++;
//Loop End

Some values are INT some are String etc.

I just want to know is is bad performance wise ? In other words ....

is setObject(1, "ABC") slower than setString(1 , "ABC")? Especially if there are a millions of bindings in a Loop?

Thanks in advance!

Boris Pavlović
  • 63,078
  • 28
  • 122
  • 148
Noman K
  • 277
  • 1
  • 5
  • 15
  • 1
    Related: http://stackoverflow.com/questions/5927363/java-resultset-setobject-vs-setstring-setdate-etc?rq=1 – Pimgd Jul 14 '14 at 11:15
  • Have you tested the performance of these two approaches? – Boris Pavlović Jul 14 '14 at 11:15
  • cant test easily because I will have to change to code a lot – Noman K Jul 14 '14 at 11:26
  • A little difference in time may occur basically in millisecs I am not sure of the exact reason but may be because in the case of preparedStatement.setString() or preparedStatement.setInt the JVM already knows of the type to deal with but in the later case it first clarifies the type and then acts accordingly. This may cause a little wastage of time i'm not quite sure here – SparkOn Jul 14 '14 at 11:32
  • There probably is a minor performance impact for using `setObject`, and it might vary per JDBC driver. Only way to find out for sure is to benchmark it thoroughly – Mark Rotteveel Jul 15 '14 at 07:23
  • @M.Sharma Technically the JVM doesn't 'clarify the type', this is explicitly programmed (eg using `instanceof`) in the specific JDBC driver implementation used. – Mark Rotteveel Jul 15 '14 at 07:24
  • @Mark Rotteveel Not quite sure what happens there actually as I said it was just an assumption someone can correct me if I am wrong – SparkOn Jul 15 '14 at 07:31

0 Answers0