Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the difference

 
parul patidar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

and

what is the difference betn these two blocks in terms of efficiency or both ways are equally efficient?
 
parul patidar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by parul patidar:

what is the difference betn these two blocks in terms of efficiency or both ways are equally efficient?

or none of the way is efficient?
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the second case, ur statement object is local to the while block and not available outside the while loop.
If you declare 's' outside the while loop, it can be used even outside the loop.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by parul patidar:
or none of the way is efficient?

they are different, but are both inefficient.
The firstStatement:

will reuse the same memory address for each iteration through the while statement.
the second statement:

will create a new object in memory for each iteration.
Performance:
both of the above use statements, which means that in each iteration it has to create the statement object, then compile it, then eventually execute it.
Better performance:

will create only one object in memory and reuse it for each iteration.
If you use PreparedStatement instead, you can create an object once, compile it once, then reuse it.
eg.

The best performance:
use preparedStatements with BatchUpdates.(only applicable to some JDBC drivers).
Jamie
 
parul patidar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx u really helped a lot
Originally posted by Jamie Robertson:
[B]
will create only one object in memory and reuse it for each iteration.
[/CODE]
Jamie[/B]

can i use same statement to fire more than one sql commands
 
Suji N
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou Jamie
You explained very clearly about usuage of statements in jdbc
i learned a lot from that
Thankyou once again
Yours
Suji
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic