TYPES OF JDBC STATEMENTS

INTRODUCTION FOR TYPES OF JDBC STATEMENTS

Their are threeTYPES OF JDBC STATEMENTS such as:

  1. Statement
  2. Prepared Statement
  3. Collable Statement

1. STATEMENT:

It is used as a general-purpose for accessing the Database. STATEMENT is good and useful when using static sql statement in runtime.

Example for STATEMENT is as follow:

Class.forName (“Driver String”);

Connection con=DriverManager.getConnection(“con string”, “un”, “pwd”) ;

Statement st=con.createStatement();

String sql=”query”;

st.executeQuery(sql);

st.executeupdate(sql);

con.close();

st.close();


2. Prepared Statement:

Many time we plan to use same sql statement so the Prepared Statement can be used. it accepts input parameters at runtime.

Example for PREPARED STATEMENT is as follow:

Class.forName (“Driver String”);

Connection con=DriverManager.getConnection(“con string”, “un”, “pwd”) ;

String sql=”select * from student”

PreparedStatement ps=con.preparedStatement(sql);

ps.setInt (1,1001);

ResultSet rs=ps.executeQuery();

int i=ps.executeUpdate();

con.close();

ps.close();


3. Collable Statement:

When Database Stored Procedure is access than the Collable Statement is used.

Example for COLLABLE STATEMENT is as follow:

Class.forName (“Driver String”);

Connection con=DriverManager.getConnection(“con string”, “un”, “pwd”) ;

String sql=”select * from student”

CollableStatementStatement cs=con.preparecall ({call proc_name(?)})

cs.setInt(1,1001);

int x=cs.execute();

con.close();

cs.close();


IF YOU WANT TO KNOW ABOUT SMALL AND RELIABLE PROJECT PLEASE VISIT HERE.

MORE EXAMPLE FOR HAMMING CODE IN THIS WEBSITE.

Leave A Reply

Your email address will not be published. Required fields are marked *