Interview Questions  

Go Back   Interview Questions > Interview Questions & Answers > Information Technology > Java > JDBC

JDBC JDBC Interview Questions, Learn by sharing JDBC Interview Questions asked in various companies, Get Career advices, Interview Procedures from JDBC experts, Post asked JDBC Interview Questions and Answers.

   

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-25-2008, 08:25 PM
Senior Member
 
Join Date: Mar 2008
Posts: 4,634
Default What is difference between PreparedSta

What is difference between PreparedStatement and Statement ?
Reply With Quote
  #2 (permalink)  
Old 06-26-2008, 09:06 AM
Junior Member
 
Join Date: Jun 2008
Posts: 6
Default

by using statement we can execute only one statement whereas by using we can execute more than one statement using in JDBC
Reply With Quote
  #3 (permalink)  
Old 06-26-2008, 01:56 PM
Junior Member
 
Join Date: Jun 2008
Location: pune
Posts: 5
Default

preparedStatement is a pre compiled statement
and Statement is not a pre compiled statement
so preparedStatement is more faster and give better performance
Reply With Quote
  #4 (permalink)  
Old 06-27-2008, 06:59 PM
Junior Member
 
Join Date: Jun 2008
Posts: 16
Default

Statements:execute simple SQL without parameters
PreparedStatement:used for pre-compiled SQL with or without parameters.
Reply With Quote
  #5 (permalink)  
Old 07-07-2008, 10:23 AM
Junior Member
 
Join Date: Jul 2008
Posts: 1
Send a message via Yahoo to Ashish P J
Default

you can pass parameters(like column name) at run time
using preparedstatement.its not possible with statement.
Reply With Quote
  #6 (permalink)  
Old 07-17-2008, 06:13 AM
Member
 
Join Date: Jul 2008
Location: West Bengal,India
Posts: 48
Default

both are objects for sending SQL statements to the database.
using statement we can send only one query to database but using PreparedStatement we can change the parameter of the query.
ex.(from java.sun.com )

PreparedStatement updateSales;
String updateString = "update COFFEES " +
"set SALES = ? where COF_NAME like ?";
updateSales = con.prepareStatement(updateString);
int [] salesForWeek = {175, 150, 60, 155, 90};
String [] coffees = {"Colombian", "French_Roast", "Espresso",
"Colombian_Decaf", "French_Roast_Decaf"};
int len = coffees.length;
for(int i = 0; i < len; i++) {
updateSales.setInt(1, salesForWeek[i]);
updateSales.setString(2, coffees[i]);
updateSales.executeUpdate();
}
Reply With Quote
Reply

Tags
interview questions, jdbc

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On