Ads Sponsored By Google :)

Saturday, 20 July 2013

PreparedStatement in Java, JDBC Examples tutorials

Prepared Statement, prepared statement example, prepared statement java, java prepared statement,  jdbc prepared statement, prepared statement in java, sql prepared statement, prepared statement postgresql prepared statement, PreparedStatement in java tutorial, PreparedStatement in JDBC, Difference between PreparedStatement and Callable Statement, CallableStatement Vs Prepared Statement.

Prepared Statement in JDBC : 

Prepared Statement is an interface extended from Statement interface.
1) PreparedStatement transfers numbers, String, dates and large objects between java application and database.
2) PreparedStatement Pre Compiles an Sql statement and that query can be executed from any number of times by recompilation again. It means PreparedStatement increases the performance of an Application
3) A Prepared Statement allows to put Parameters (?,?,?) into sql query to make it as dynamic whenever we want to run same query for multiple number of times, PreparedStatement Performance is better than Statement.

Example program for Prepared Statement :
import java.util.*;  // Util package
import*; // IO Pacakage
import java.sql.*; // it is used for all JDBC Connection.
Class JdbcDemo1{
  Public static void main(String args[]) throws Exception{
Connection con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:XE”,”scott”,”tiger”);
PreparedStatement pstmt=con.preparedStatement(“insert  into emp values(?,?,?)”);
// Inserting the data dynamically using “?”.
Scanner s=new Scanner(;
System.out.println(“Enter the Company Id”);
Reading the data dynamically for ?,?,?

No comments:

Post a Comment