• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Binding values in a PreparedStatement

 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Coming from the world of C, I just wanted to verify that I have this right.
In C and using OCI calls, I would bind the values of a statement by registering place-holders with an address in memory, something like:
bind_var(stmt_hanlde, 1, &value_address, ....);
Where the first argument is the statement handle, followed by the position (or index), followed by the address where to get the value, followed by other options.
Then I would process:
for all records ...
loop
value_address = record.value
execute(stmt_handle)
end loop
It seems to me the bind_var() is an equivelent to JDBC's setXXX() methods.My question is:
Is there a way to bind only once (and each time through the loop just change the value of the object) or must you always use the setXXX() methods each time through the loop?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're using the same PreparedStatement in a loop, right? Just use the setXXX() methods. If a given field is constant throughout the loop, invoke the appropriate setXXX() just before the loop, and don't change it after. If it varies with each iteration of the loop, invoke the approriate setXXX() within the loop rather than before it. In general, PreparedStatement remembers the last thing you told it about any given field, so you can construct your calls accordingly.
[ July 16, 2002: Message edited by: Jim Yingst ]
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jim Yingst:
You're using the same PreparedStatement in a loop, right? Just use the setXXX() methods.

Yes, I am in a loop and I guess that what I would
normally do in C with:

value_address = record.value

Get's replaced in JDBC with:

setXXX(i, record.value)

Thanks,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic