title: how to pass the value dynamically to sp using java?
body: <p><strong>I want to pass the value to sp parameter dynamically. is it possible with CallableStatement and PreparedStatement?</strong></p>
  
  <pre><code>Connection con=null;
  Drivername="com.microsoft.sqlserver.jdbc.SQLServerDriver";.
  Connectionname="jdbc:sqlserver://localhost:1433;databaseName=test;
  Class.forName(Drivername);
  con = DriverManager.getConnection(Connectionname,USER_NAME, PWD); 
  PreparedStatement pstmt = con.prepareStatement("sp_help sp_emp_det");
  ResultSet rs = pstmt.executeQuery();
  List&lt;String&gt; lstint= new ArrayList&lt;String&gt;();
  pstmt.getMoreResults(); //returns set of resultset in boolean
  rs = pstmt.getResultSet();
  while(rs.next())
  {
      System.out.println(rs.getString(2)); //checking input parameter list
      lstint.add(rs.getString(2)); // getting list of parameter's datatype from sp and push into Arraylist
  }
  pstmt = con.prepareStatement("{call sp_emp_det(?,?,?)}");
  for (int i=1; i&lt;=lstint.size() ; i++ )
  {
  pstmt.setString(i,lstValue.get(i-1));
  }
  rs = pstmt.executeUpdate(); //throws error on here which mentioned below
  //to retrive resultset from the sp
  while(rs.next())
  {
  String s=rs.getString(1);
  System.out.println("s : "+s);
  }
  </code></pre>
  
  <p><strong>if I use executeUpdate() insteadof executeQuery()
      Execute_SP.java:43: incompatible types
      found   : int
      required: java.sql.ResultSet
      ResultSet rs = pstmt.executeUpdate();</strong></p>
  
  <p>if I use executeQuery() above code, it returns the resultset and display the value of s from backend</p>
  
  <p>I'm trying get list of input parameters from sp which works fine and trying to pass the values to the parameters dynamically</p>
  
  <p>list of parameters for the sp</p>
  
  <pre><code>Parameter_name Type
  @ename         nvarchar
  @position      varchar
  @expr          int
  </code></pre>
  
  <p>if use below with exceuteUpdate() : which works fine</p>
  
  <pre><code>pstmt.setString(1,"");
  pstmt.setString(2,"");
  pstmt.setInt(3,0);
  </code></pre>
  
  <p>Kindly help me to solve this problem.</p>