views:

19

answers:

1

Given this java code...

PreparedStatement s = prepare("SELECT ...")
ResultSet r = s.executeQuery()
r.next()
s = prepare("UPDATE ...")
s.setInt(1, r.getInt(3))
s.setInt(2, r.getInt(1))
s.executeUpdate()
s = prepare("UPDATE ...")
s.setInt(1, r.getInt(3))
s.setInt(2, r.getInt(2))
s.executeUpdate()

It seems to me that MySQL JDBC would have to do ...intValue() and new Integer(..). Does anybody know if the above code would perform better if I used setObject/getObject instead. What about any other types?

I expect to be using JDBC for years to come so I thought I might as well stop guessing.

A: 

The signatures on getInt() and setInt() are native ints, not Object or Integer. Frankly, the overhead of creating an object compared to doing a query would be very tiny. If I was concerned about the performance here, I'd try to combine the SELECT with the UPDATE here and do this in one statement on the server.

Joshua Martell