1 posts in topic
Flat View  Flat View

Posted By:   Asm_Asud
Posted On:   Thursday, April 10, 2008 03:43 AM

Hi all,
Consider two cases of a PreparedStatement:

Case 1:

connection.prepareStatement("Select * FROM" + test);

Case 2:

connection.prepareStatement("Select * FROM ?" );
preparedStatement.setString(1, test);

where test is the table name sent dynamically.
Can anyone please tell me what is the difference in the two code snippets?

Thanks in advance

Re: PreparedStatement

Posted By:   Amit_Patel  
Posted On:   Thursday, April 10, 2008 01:21 PM

Hi Asm Asud,

If you use above two code snippet in your application, from result prespective there in no difference.

But as might you know that PrepareStatement is the one which will compiled only once and you can use it's setXXX() method to set the value dynamically.

The main difference between above tow code snippet is that, in
Case 1 : the prepare statement is going to compile everytime and new prepare statement is going to be created.

While in Case 2: , after executing 1st line statement is compiled and you can use it after wards, you just need to set the value.

Hope so this will clarify your doubts.

Thanks and Regards,

Amit Patel

About | Sitemap | Contact