title: What is the use of cstmt.registerOutParameter(2, Types.VARCHAR);
body: <p>I'm using a Stored Procedure(InOut).. im little bit confused with the line cstmt.registerOutParameter(2,Types.VARCHAR);//why we write registerOutParameter and is it necessary to write the data type of that parameter like Types.VARCHAR</p>
  
  <p>My Stored Procedure</p>
  
  <pre><code> CREATE DEFINER=`root`@`localhost` PROCEDURE `Rinout`(in p1  int, inOut p2 varchar(25))
      begin
      UPDATE sush SET address = p2 WHERE id = p1;
      SELECT address INTO p2 FROM sush WHERE id = p1;
      end$$
      DELIMITER ;
  </code></pre>
  
  <p>My Servlet Code</p>
  
  <pre><code>package com.ravi;
  
  import java.sql.*;
  
  public class Spinout
  { static
      {
      //STEP 1 : Registering The Driver Class
  
      try
      {
          Class.forName("com.mysql.jdbc.Driver");
      }
      catch (ClassNotFoundException e)
      {
          System.out.println("Unable To Load The Driver class");
      }
  }
  
  public static void main(String[] args)
  {
      Connection con = null;
  
      CallableStatement cstmt = null;
  
      try
      {
          //Database Credentials
  
          String URL = "jdbc:mysql://localhost:3306/ravi";
  
          String username = "root";
  
          String password = "root";
  
          //STEP 2 : Creating The Connection Object
  
          con = DriverManager.getConnection(URL, username, password);
              //STEP 3 : Creating The CallableStatement Object
  
              cstmt = con.prepareCall("{call Rinout(?, ?)}");
  
              //Setting IN Parameters
  
              cstmt.setInt(1, 1);
  
              cstmt.setString(2, "WGL");
  
              //Registering OUT parameters
  
              cstmt.registerOutParameter(2, Types.VARCHAR);
  
              //STEP 4 : Executing The CallableStatement
  
              cstmt.execute();
  
              //Retrieving OUT parameter
  
              String grade = cstmt.getString(2);
  
              System.out.println(grade);
          }
          catch (SQLException e)
          {
              e.printStackTrace();
          }
          finally
          {
              //STEP 5 : Closing The DB Resources
  
              //Closing the CallableStatement object
  
              try
              {
                  if(cstmt!=null)
                  {
                      cstmt.close();
                      cstmt=null;
                  }
              }
              catch (SQLException e)
              {
                  e.printStackTrace();
              }
  
              //Closing the Connection object
  
              try
              {
                  if(con!=null)
                  {
                      con.close();
                      con=null;
                  }
              }
              catch (SQLException e)
              {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>
  
  <p>The above is working fine but I want to know why we are using cstmt.registerOutParameter(2,Types.VARCHAR);</p>