Last active
December 24, 2015 11:29
-
-
Save swapnil-webonise/6791623 to your computer and use it in GitHub Desktop.
Call Stored Function Using Servlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examadmin; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import org.json.JSONArray; | |
import java.sql.Connection; | |
import java.sql.ResultSet; | |
import java.sql.PreparedStatement; | |
import java.sql.CallableStatement; | |
import java.sql.SQLException; | |
public class checkplanstatus extends HttpServlet | |
{ | |
private static final long serialVersionUID = 1L; | |
Connection conn; | |
ResultSet rs; | |
PreparedStatement ps; | |
CallableStatement cs; | |
public checkplanstatus() | |
{ | |
super(); | |
conn = ExamConnection.getConnection(); | |
System.out.println("connection successfully"); | |
} | |
public void process(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException | |
{ | |
try | |
{ | |
String planId = request.getParameter("planId"); | |
String simpleProc = "{? = CALL test.checkplanstatusnew('"+planId+"')}"; | |
cs = conn.prepareCall(simpleProc); | |
rs= cs.executeQuery(); | |
JSONArray jarray = new JSONArray(); | |
while(rs.next()) | |
jarray.put(rs.getInt(1)); | |
PrintWriter out = response.getWriter(); | |
out.print(jarray); | |
} | |
catch(SQLException es) | |
{ | |
System.out.println(es); | |
} | |
} | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException | |
{ | |
this.process(request, response); | |
} | |
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException | |
{ | |
this.process(request, response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment