title: Stored Procedure : Invalid column index
body: <p>(JAVA)I have a DBConnection class and a main class.
  In DBConnection class, connection  to db made via constructor.</p>
  
  <pre><code>public class DBConnection {
  
  private static final String DEFAULT_DRIVER = "oracle.jdbc.driver.OracleDriver";
  private static final String DEFAULT_URL = "jdbc:oracle:thin:@IP:PORT:TesttDb";
  private static final String DEFAULT_USERNAME = "est";
  private static final String DEFAULT_PASSWORD = "est";
  private Connection conn = null;
  
  public DBConnection() {
  
  try {
  Class.forName(DEFAULT_DRIVER);
  String url = DEFAULT_URL;
  Properties props = new Properties();
  props.setProperty("user", DEFAULT_USERNAME);
  props.setProperty("password", DEFAULT_PASSWORD);
  conn = DriverManager.getConnection(url, props);
  } 
  catch (ClassNotFoundException | SQLException ex) {
  System.out.println(ex);
  }
  }
  
  
   public ResultSet getDetails(int id) throws SQLException
      {
          CallableStatement cs;
          cs=conn.prepareCall("{call GET_DETAILS(?,?,?,?)}");
          cs.setInt(1, id);
          cs.registerOutParameter(2, Types.VARCHAR);
          cs.registerOutParameter(3, Types.VARCHAR);
          cs.registerOutParameter(4, Types.INTEGER);
          ResultSet rs=cs.executeQuery();
          System.out.println(cs.getObject(1));
  
          return rs;
  
      }
  </code></pre>
  
  <p>and my main class is </p>
  
  <pre><code>public class DBMain {
  
  public static void main(String arg[]) {
  try {
  DBConnection dBConnection = new DBConnection();
  CallableStatement cs=dBConnection.getDetails(1);
  System.out.println(cs.getObject(1));
  } catch (Exception ex) {
  System.out.println(ex);
  }
  }
  }
  </code></pre>
  
  <p>here connection is ok..</p>
  
  <p>my stored procedure is</p>
  
  <pre><code>CREATE PROCEDURE GET_DETAILS
  (
  P_ID IN SAMPLE.ID%TYPE,
  P_NAME OUT SAMPLE.NAME%TYPE,
  P_ADDRESS OUT SAMPLE.ADDRESS%TYPE,
  P_AGE OUT SAMPLE.AGE%TYPE
  )
  AS
  BEGIN
  SELECT
  NAME,ADDRESS,AGE INTO P_NAME,P_ADDRESS,P_AGE
  FROM SAMPLE
  WHERE SAMPLE.ID=P_ID;
  END;
  /
  </code></pre>
  
  <p>my database table is</p>
  
  <pre><code>SQL&gt; desc sample
   Name                            Null?    Type
   ------------------------------- -------- ----
   ID                              NOT NULL NUMBER(5)
   NAME                            NOT NULL VARCHAR2(20
   ADDRESS                         NOT NULL VARCHAR2(20
   AGE                             NOT NULL NUMBER(5)
  </code></pre>
  
  <p>I have one row in table with <code>id=1</code></p>
  
  <p>but after executing the main method. I am getting an exception </p>
  
  <pre><code>run:
  java.sql.SQLException: Invalid column index
  BUILD SUCCESSFUL (total time: 0 seconds)
  </code></pre>
  
  <p>any idea or help will be highly appreciated.</p>