aspose file tools*
The moose likes JDBC and the fly likes what is the difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "what is the difference " Watch "what is the difference " New topic
Author

what is the difference

parul patidar
Ranch Hand

Joined: Sep 07, 2001
Posts: 53

and

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

Joined: Sep 07, 2001
Posts: 53
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

Joined: Jun 07, 2000
Posts: 87
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

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Sep 07, 2001
Posts: 53
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

Joined: Sep 04, 2001
Posts: 35
Thankyou Jamie
You explained very clearly about usuage of statements in jdbc
i learned a lot from that
Thankyou once again
Yours
Suji
 
jQuery in Action, 2nd edition
 
subject: what is the difference