How can i pass the values in string parameters to a stored procedure
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How can i pass the values in string parameters to a stored procedure

  1. #1
    Join Date
    Apr 2017
    Posts
    4

    How can i pass the values in string parameters to a stored procedure

    jsp code

    <table align="center">
    <tr>
    <td>Select An Item :</td>
    <td> <select name="comments" multiple>
    <option value="comment1">I am an intelligent</option>
    <option value="comment2">I am a brave person</option>
    <option value="comment3">I am a hard worker</option>
    <option value="comment4">I am a timid person</option>
    </select>
    </td>
    </tr>
    <tr>
    <td><input type="submit" value="Send"></td>
    <td></td>
    </tr>
    <tr><td><label for="fileName">Select From Date: </label>
    <input id="datepicker" name="pickedDate"/> </td><br/>
    <td><label for="fileName">Select To Date: </label>
    <input id="datepicker1" name="pickedDate1"/> </td><br/></tr>
    </table>


    servlet code

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    try
    {
    SQLServerDataSource ds = new SQLServerDataSource();
    Connection conn=null;
    ds.setUser("");
    ds.setPassword("");
    ds.setServerName("");
    ds.setDatabaseName("");
    conn = ds.getConnection();
    conn.setAutoCommit(true);
    Statement st=conn.createStatement();
    System.out.println("Connected!");
    String users[] = request.getParameterValues("comments") ;
    String FromDate = request.getParameter("pickedDate");
    String ToDate = request.getParameter("pickedDate1");
    PrintWriter writer = response.getWriter();
    response.setContentType("text/html");
    writer.println("<h4>You are selected :</h4>");
    for(String selecteduser :users)
    {
    writer.println("<br><font color=black>"+selecteduser+"</font>");
    }
    ArrayList al = null;
    ArrayList pid_list = new ArrayList();

    //stored procedure
    String query = ""dbo.users", "@fromdate", FromDate , "@Todate", ToDate , "@Users",users[]";



    writer.close();
    }
    catch(Exception exception)
    {
    exception.printStackTrace();
    }
    }

  2. #2
    Join Date
    Aug 2017
    Posts
    36

    Re: How can i pass the values in string parameters to a stored procedure

    It is very good program very easy to understand. I will definitely try this in my project.

  3. #3
    Join Date
    Aug 2017
    Posts
    36

    Re: How can i pass the values in string parameters to a stored procedure

    Procedure Name : Users
    Parameters : @fromdate , @Todate,@Users

    this is what i did try (CallableStatement s = conn.prepareCall("{CALL Users(@fromdate=?,@Todate=?,@Users=?)}")) {
    s.getDate(FromDate);
    s.getDate(ToDate);
    s.getstring(Users)
    try (ResultSet rs = s.executeQuery()) {
    rs.next();
    System.out.println(rs.getString("response"));
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)