package com.sawan; import java.io.IOException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Enumeration; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONObject; @WebServlet("/DirectorStudentList") public class DirectorStudentList extends HttpServlet { private static final long serialVersionUID = 1L; Statement stmt = null; public DirectorStudentList() { super(); // TODO Auto-generated constructor stub } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONObject json = new JSONObject(); Enumeration paramNames = request.getParameterNames(); String params[] = new String[3]; int i = 0; while (paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); System.out.println(".........params[]....................."+paramName); System.out.println(paramName); String[] paramValues = request.getParameterValues(paramName); params[i] = paramValues[0]; System.out.println(".............+params[i]................."+params[i]); System.out.println(".............+params[i]................."+params[i]); System.out.println(params[i]); i++; } ResultSet rs=null; String table=params[1]; String cutoff=params[0]; DataBase db=new DataBase(); Connection con=db.getConnection(); table=table; String Roll=params[0]; int code=Integer.parseInt(params[0]); System.out.println("rOLL nO............"+Roll); String sql="SELECT * FROM Attendance."+table+" WHERE STUDENTBRANCH ="+code+" AND STUDENTSECTION='"+params[2]+"'"; System.out.println(sql); try { stmt=con.createStatement(); rs = stmt.executeQuery(sql); } catch (SQLException e1) { e1.printStackTrace(); } try { System.out.println("STEMENT EXECUTE.............."); System.out.println("RESULT SET EXECUTR.............."); int u=0; int s=0; while (rs.next()) { json.put("name"+s,rs.getString("STUDENTNAME")); json.put("roll"+s,rs.getString("STUDENTROLL")); json.put("info", "success"); s++; json.put("row",s); System.out.println("RESULT SET EXECUTR.......2......."); u=1; } if(u==0) { json.put("info", "fail"); } System.out.println("RESULT SET EXECUTR.........24....."); } catch (Exception e) { e.printStackTrace(); } System.out.println(json); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(json.toString()); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } }
Search the Blog
Sunday, July 28, 2019
MVC CODE FOR ANDROID REQUEST AND RESPONSE -Programming Logic and Code with Syntax Dizsweb
Labels:
Code,
CSS,
database,
DIZSWEB,
HTML,
INFORMATION QUERY,
Interview,
JAVA,
JavaScript,
JS,
Online Exam,
Ouery,
Query Optimization,
SERVERS,
SQL
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment