• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What's the difference between pstmt.setObject() and pstmt.setInt()?

 
Gary Kevin
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my code,of course this's right if I write like this:





I want to know if there is any problem if I write like this?What's the difference between them?and how about the efficiency?
 
Scott Selikoff
author
Saloon Keeper
Posts: 4033
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its riskier because the data might not get converted in a way you want it to. Keep in mind different calls, setString, setInt, and setDate for example, do different things. setString adds quotes around the variable and converts single quotes to double whereas setDate converts to the proper date format.

Its possible by using setObject for the the conversion to happen incorrectly and/or an error from an inability to know how to convert an object.

Efficiency isn't really going to matter, its more a matter of stability and code supportability.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4033
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and "Odysseus JL",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
Scott
 
Gary Kevin
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott Selikoff :
Thanks,I'll adjust my display name. :p
 
Scott Selikoff
author
Saloon Keeper
Posts: 4033
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't mean to nitpick too much, but you could please add a space between you first and last name? Its part of the naming policy that there be a space inbetween.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic