-
July 27th, 2017, 03:58 AM
#1
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();
}
}
-
September 8th, 2017, 01:28 AM
#2
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.
-
September 12th, 2017, 01:52 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|