What is JDBC prepared statement ?

The prepared statement is also called as precompiled statement because it is already complied.

In prepared statement the sql query send to the database then the database complied and store it for future preference And return the complied query to prepared statement.

In prepared statement the query complied once and there is no need of write the code again at the time of execution even if we write the execution code for thousand times.


PreparedStatement stmt=con.prepareStatement("Sql Query goes here.");


import java.sql.*; 
 class MysqlCon{ 
 public static void main(String args[]){  
   Connection con=DriverManager.getConnection( “jdbc:mysql://localhost:3306/students","root","Students@123");
     PreparedStatement stmt=con.prepareStatement("select * from students_data"); 
 ResultSet rs=stmt.executeQuery();
  System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3)); 
  catch(Exception e){ System.out.println(e);}