JAVA Code for Update of details With SQL CODE AND Responce
package com.sawan;
import java.io.IOException;
import java.sql.Connection;
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.JSONException;
import org.json.JSONObject;
@WebServlet("/Admindetailupdate")
public class Admindetailupdate extends HttpServlet {
private static final long serialVersionUID = 1L;
Statement st;
public Admindetailupdate() {
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[11];
int i = 0;
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
params[i] = paramValues[0];
i++;
}
String table = params[0];
table = table.substring(0, 11);
DataBase db = new DataBase();
Connection con = db.getConnection();
try {
st = con.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (true) {
String sql = "UPDATE attendance" + "." + table + " SET STUDENTFATHER='" + params[2] + "',"
+ "MotherName='" + params[3] + "',"
+ "DOB='" + params[4] + "'," + "GENDER='" + params[5] + "'," + "STUDENTEMAIL='" + params[6] + "',"
+ "STUDENTFATHERMOB='" + params[7] + "'," + "STUDENTMOB='" + params[8] + "'," + "ADARCARD='"
+ params[9] + "'," + "ADDRESS='" + params[10] + "'"
+ " where STUDENTROLL='" + params[1] + "'";
int u = 0;
try {
u = st.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (u != 0) {
try {
json.put("info", "success");
} catch (JSONException e) {
e.printStackTrace();
}
} else {
try {
json.put("info", "failure");
} catch (JSONException e) {
e.printStackTrace();
}
}
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json.toString());
} else if (params[16].equals("Student")) {
String sql = "UPDATE attendance" + "." + table + " SET STUDENTBRANCH=" + params[3] + ","
+ "STUDENTSECTION='" + params[4] + "'" +
" where STUDENTROLL='" + params[2] + "'";
System.out.println("sql query is : " + sql);
int u = 0;
try {
u = st.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (u != 0) {
try {
json.put("info", "success");
} catch (JSONException e) {
e.printStackTrace();
}
} else {
try {
json.put("info", "failure");
} catch (JSONException e) {
e.printStackTrace();
}
}
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json.toString());
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
JAVA Code Direct Attendance update with Server Response and SQL Update
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("/AdminAttendanceStudentList")
public class AdminAttendanceStudentList extends HttpServlet {
private static final long serialVersionUID = 1L;
Statement stmt = null;
public AdminAttendanceStudentList() {
super();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
JSONObject json = new JSONObject();
Enumeration paramNames = request.getParameterNames();
String params[] = new String[3];
int i = 0;
while (paramNames.hasMoreElements())
{
String paramName = (String) paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
params[i] = paramValues[0];
i++;
}
ResultSet rs=null;
String table=params[1];
String cutoff=params[0];
DataBase db=new DataBase();
Connection con=db.getConnection();
table=table.substring(0, 11);
String Roll=params[0];
int code=Integer.parseInt(params[0]);
String sql="SELECT * FROM attendance."+table+" WHERE STUDENTBRANCH ="+code+" AND STUDENTSECTION='"+params[2]+"'";
try {
stmt=con.createStatement();
rs = stmt.executeQuery(sql);
int u=0;
int s=0;
while (rs.next()) {
json.put("home"+s,rs.getString("STUDENTNAME"));
json.put("homec"+s,rs.getInt("STUDENTBRANCH"));
json.put("homes"+s,rs.getString("STUDENTSECTION"));
json.put("no",s);
u=1;
s++;
}
if(u==0)
{
json.put("info", "fail");
}
else
{
json.put("info","success");
}
} catch (Exception e) {
e.printStackTrace();
}
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json.toString());
}
}
JAVA Code Attendance with Server Response and SQL Update
package com.sawan;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Enumeration;
import java.util.Iterator;
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.JSONException;
import org.json.JSONObject;
@WebServlet("/AdminappAttendanceUpdate")
public class AdminappAttendanceUpdate extends HttpServlet {
private static final long serialVersionUID = 1L;
Statement st = null;
ResultSet rs;
JSONObject json = new JSONObject();
public AdminappAttendanceUpdate() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Enumeration paramNames = request.getParameterNames();
ArrayList<String> params = new ArrayList<String>();
int i = 0;
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
params.add(paramValues[0]);
i++;
}
int ror = 0;
int length = 0;
Iterator itr = params.iterator();
Iterator itr2 = params.iterator();
while (itr.hasNext()) {
length++;
itr.next();
}
int m = 0;
String arr[] = new String[length];
while (itr2.hasNext()) {
arr[m] = (String) itr2.next();
m++;
}
String facultyCode = arr[length - 1];
String table = arr[length - 2];
int row = Integer.parseInt(arr[length - 3]);
table = table.substring(0, 11);
DataBase db = new DataBase();
Connection con = db.getConnection();
int u = 0;
try {
st = con.createStatement();
int t = 0;
for (int j = 0; j < row; j++) {
int att = Integer.parseInt(arr[t + 4]);
String sql2 = "select * from attendance." + table + " where STUDENTROLL='" + arr[t + 1] + "'";
PreparedStatement stmt = con.prepareStatement(sql2);
rs = stmt.executeQuery();
rs.next();
int valueattt = 0;
int atte = rs.getInt("STUDENTHIGH");
int atte2 = rs.getInt("STUDENTSEMESTER");
if (Integer.parseInt(arr[t + 4]) == 0) {
atte = atte;
atte2 = atte2 + 1;
} else {
valueattt = 1;
atte = atte + 1;
atte2 = atte2 + 1;
}
String sql = "UPDATE attendance" + "." + table + " SET STUDENTHIGH=" + atte + " ,STUDENTSEMESTER="
+ atte2 + " WHERE STUDENTROLL='" + arr[t + 1] + "'";
st.executeUpdate(sql);
String date = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
String redate2[] = date.split("_");
char[] ch = redate2[0].toCharArray();
String date3 = ch.toString();
String year = redate2[0].substring(0, 4);
String month = redate2[0].substring(4, 6);
String day = redate2[0].substring(6);
String redate = day + "/" + month + "/" + year;
String sql3 = "INSERT INTO attendance" + "." + table + "record (STUDENTROLL,STUDENTNAME,"
+ "SUBJECTCODE,FACULTYCODE,LACTUREDAY,LACTUREMONTH,LACTUREYEAR,LACTURETIME,LACTUREVARIFICATION) VALUES(?,?,?,?,?,?,?,?,?)";
PreparedStatement pst = con.prepareStatement(sql3);
pst.setString(1, arr[t + 1]);
pst.setString(2, "");
pst.setInt(3, 1);
pst.setInt(4, 1);
pst.setString(5, day);
pst.setString(6, month);
pst.setString(7, year);
pst.setString(8, redate2[1]);
if (valueattt == 0) {
pst.setInt(9, 0);
} else {
pst.setInt(9, 1);
}
pst.execute();
pst.close();
u = 1;
t = t + 5;
}
} catch (SQLException e) {
u = 0;
e.printStackTrace();
}
if (u != 0) {
try {
json.put("info", "success");
} catch (JSONException e) {
e.printStackTrace();
}
} else {
try {
json.put("info", "failure");
} catch (JSONException e) {
e.printStackTrace();
}
}
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json.toString());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
JAVA Code Academic Calendar with Server Response and SQL Update with admin delete authority
package com.sawan;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
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.JSONException;
import org.json.JSONObject;
/**
* Servlet implementation class AdminAccountDelete
*/
@WebServlet("/AdminAccountDelete")
public class AdminAccountDelete extends HttpServlet {
private static final long serialVersionUID = 1L;
PreparedStatement st = null;
public AdminAccountDelete() {
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[17];
int i = 0;
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
params[i] = paramValues[0];
i++;
}
if (params[2].equals("sawan1")) {
String table = params[0];
table = table.substring(0, 11);
table = table + "DI";
DataBase db = new DataBase();
int u = 0;
Connection con = db.getConnection();
try {
String sql = "DELETE FROM attendance" + "." + table + " WHere STUDENTFNAME=?";
PreparedStatement preparedStmt = con.prepareStatement(sql);
preparedStmt.setString(1, params[1]);
preparedStmt.execute();
u = 1;
} catch (SQLException e) {
u = 0;
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if (u == 0) {
json.put("info", "failure");
} else {
json.put("info", "success");
}
} catch (Exception e) {
e.printStackTrace();
}
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json.toString());
}
if (params[2].equals("sawan2")) {
String table = params[0];
table = table.substring(0, 11);
table = table + "HO";
DataBase db = new DataBase();
int u = 0;
Connection con = db.getConnection();
try {
String sql = "DELETE FROM attendance" + "." + table + " WHere STUDENTFNAME=?";
PreparedStatement preparedStmt = con.prepareStatement(sql);
preparedStmt.setString(1, params[1]);
preparedStmt.execute();
u = 1;
} catch (SQLException e) {
u = 0;
e.printStackTrace();
}
try {
if (u == 0) {
json.put("info", "failure");
} else {
json.put("info", "success");
}
} catch (Exception e) {
e.printStackTrace();
}
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json.toString());
}
if (params[2].equals("sawan3")) {
String table = params[0];
table = table.substring(0, 11);
table = table + "FA";
DataBase db = new DataBase();
int u = 0;
Connection con = db.getConnection();
try {
String sql = "DELETE FROM attendance" + "." + table + " WHere STUDENTFNAME=?";
PreparedStatement preparedStmt = con.prepareStatement(sql);
preparedStmt.setString(1, params[1]);
preparedStmt.execute();
u = 1;
} catch (SQLException e) {
u = 0;
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if (u == 0) {
json.put("info", "failure");
} else {
json.put("info", "success");
}
} catch (Exception e) {
e.printStackTrace();
}
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json.toString());
}
if (params[2].equals("sawan4")) {
String table = params[0];
table = table.substring(0, 11);
DataBase db = new DataBase();
int u = 0;
Connection con = db.getConnection();
try {
String sql = "DELETE FROM attendance" + "." + table + " WHERE STUDENTROLL=?";
PreparedStatement preparedStmt = con.prepareStatement(sql);
preparedStmt.setString(1, params[1]);
preparedStmt.execute();
u = 1;
} catch (SQLException e) {
u = 0;
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if (u == 0) {
json.put("info", "failure");
} else {
json.put("info", "success");
}
} catch (Exception e) {
e.printStackTrace();
}
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json.toString());
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
JAVA Code Academic Calendar with Server Response and SQL Update
package com.sawan;import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class AcademicCalendar
*/
@WebServlet("/AcademicCalendar")
public class AcademicCalendar extends HttpServlet {
private static final long serialVersionUID = 1L;
String dayss, monss, yearss;
ResultSet rs = null;
Connection con = null;
PreparedStatement stmt = null;
Statement st = null;
int sawan = 0;
public AcademicCalendar() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
DataBase db = new DataBase();
con = db.getConnection();
String datesawan = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
String redate2[] = datesawan.split("_");
char[] chsawan = redate2[0].toCharArray();
String date3sawan = chsawan.toString();
yearss = redate2[0].substring(0, 4);
monss = redate2[0].substring(4, 6);
dayss = redate2[0].substring(6);
ReadData rd = new ReadData();
if (request.getParameter("requestcode").equals("insertClassData")) {
try {
String sql2 = "insert into attendance.mpss" + request.getParameter("photo")
+ "cal (content,datee,monthh,yearr,accss) values (?,?,?,?,?)";
PreparedStatement pst = con.prepareStatement(sql2);
for (int j = 1; j <= 30; j++) {
pst.setString(1, "");
pst.setString(2, j + "");
pst.setString(3, 4 + "");
pst.setString(4, yearss);
pst.setInt(5, 0);
pst.execute();
}
for (int j = 1; j <= 31; j++) {
pst.setString(1, "");
pst.setString(2, j + "");
pst.setString(3, 5 + "");
pst.setString(4, yearss);
pst.setInt(5, 0);
pst.execute();
}
for (int j = 1; j <= 30; j++) {
pst.setString(1, "");
pst.setString(2, j + "");
pst.setString(3, 6 + "");
pst.setString(4, yearss);
pst.setInt(5, 0);
pst.execute();
}
for (int j = 1; j <= 31; j++) {
pst.setString(1, "");
pst.setString(2, j + "");
pst.setString(3, 7 + "");
pst.setString(4, yearss);
pst.setInt(5, 0);
pst.execute();
}
for (int j = 1; j <= 31; j++) {
pst.setString(1, "");
pst.setString(2, j + "");
pst.setString(3, 8 + "");
pst.setString(4, yearss);
pst.setInt(5, 0);
pst.execute();
}
for (int j = 1; j <= 30; j++) {
pst.setString(1, "");
pst.setString(2, j + "");
pst.setString(3, 9 + "");
pst.setString(4, yearss);
pst.setInt(5, 0);
pst.execute();
}
for (int j = 1; j <= 31; j++) {
pst.setString(1, "");
pst.setString(2, j + "");
pst.setString(3, 10 + "");
pst.setString(4, yearss);
pst.setInt(5, 0);
pst.execute();
}
for (int j = 1; j <= 30; j++) {
pst.setString(1, "");
pst.setString(2, j + "");
pst.setString(3, 11 + "");
pst.setString(4, yearss);
pst.setInt(5, 0);
pst.execute();
}
for (int j = 1; j <= 31; j++) {
pst.setString(1, "");
pst.setString(2, j + "");
pst.setString(3, 12 + "");
pst.setString(4, yearss);
pst.setInt(5, 0);
pst.execute();
}
for (int j = 1; j <= 31; j++) {
pst.setString(1, "");
pst.setString(2, j + "");
pst.setString(3, 1 + "");
pst.setString(4, (Integer.parseInt(yearss) + 1) + "");
pst.setInt(5, 0);
pst.execute();
}
for (int j = 1; j <= 29; j++) {
pst.setString(1, "");
pst.setString(2, j + "");
pst.setString(3, 2 + "");
pst.setString(4, (Integer.parseInt(yearss) + 1) + "");
pst.setInt(5, 0);
pst.execute();
}
for (int j = 1; j <= 31; j++) {
pst.setString(1, "");
pst.setString(2, j + "");
pst.setString(3, 3 + "");
pst.setString(4, (Integer.parseInt(yearss) + 1) + "");
pst.setInt(5, 0);
pst.execute();
}
pst.close();
request.setAttribute("roll", request.getParameter("WebStudentDetailForfeeSubmition"));
} catch (SQLException e) {
e.printStackTrace();
}
getServletContext().getRequestDispatcher("/Adminstrative.jsp").forward(request, response);
return;
} else if (request.getParameter("requestcode").equals("studentsubject")) {
String sql1 = "select * from Attendance.mpss" + request.getParameter("cid") + "cal";
try {
stmt = con.prepareStatement(sql1);
rs = stmt.executeQuery();
int calcultor = 0;
while (rs.next()) {
{
request.setAttribute("tc1" + calcultor, rs.getString("content"));
request.setAttribute("tc2" + calcultor, rs.getString("datee"));
request.setAttribute("tc3" + calcultor, rs.getString("monthh"));
request.setAttribute("tc4" + calcultor, rs.getString("yearr"));
request.setAttribute("tc5" + calcultor, rs.getString("noo"));
request.setAttribute("tc6" + calcultor, rs.getString("accss"));
calcultor++;
sawan++;
}
}
request.setAttribute("total", calcultor + "");
request.setAttribute("cid", request.getParameter("cid"));
} catch (SQLException e) {
e.printStackTrace();
}
getServletContext().getRequestDispatcher("/AcademicCalendarDataFilling.jsp").forward(request, response);
return;
} else if (request.getParameter("requestcode").equals("sawancha")) {
String sql1 = "select * from Attendance.mpss" + request.getParameter("cid") + "cal where noo="
+ Integer.parseInt(request.getParameter("seq")) + "";
try {
stmt = con.prepareStatement(sql1);
rs = stmt.executeQuery();
rs.next();
request.setAttribute("tc1", rs.getString("content"));
request.setAttribute("tc2", request.getParameter("seq"));
request.setAttribute("tc3", rs.getInt("accss"));
request.setAttribute("cid", request.getParameter("cid"));
} catch (SQLException e) {
e.printStackTrace();
}
getServletContext().getRequestDispatcher("/AcademicDataUpdation.jsp").forward(request, response);
return;
} else if (request.getParameter("requestcode").equals("schoolnoticeupdate")) {
String sql1 = "update Attendance.mpss" + request.getParameter("cid") + "cal set content='"
+ request.getParameter("PreviousMessegePaarameter") + "',accss=1 where noo="
+ Integer.parseInt(request.getParameter("seq")) + "";
try {
st = con.createStatement();
st.executeUpdate(sql1);
request.setAttribute("cid", request.getParameter("cid"));
} catch (SQLException e) {
e.printStackTrace();
}
getServletContext().getRequestDispatcher("/Adminstrative.jsp").forward(request, response);
return;
}
}
}
Code for Server Response with SQL Update Programming Logic and Code with Syntax
package com.sawan;import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
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.JSONException;
import org.json.JSONObject;
/**
* Servlet implementation class Academic
*/
@WebServlet("/Academic")
public class Academic extends HttpServlet {
private static final long serialVersionUID = 1L;
String dayss, monss, yearss;
PreparedStatement stmt = null;
ResultSet rs;
JSONObject json = new JSONObject();
public Academic() {
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[1];
int i = 0;
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
params[i] = paramValues[0];
i++;
}
String table = params[0];
table = table.substring(0, 11);
DataBase db = new DataBase();
int clsstrength = 0;
Connection con = db.getConnection();
String date = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
String redate2[] = date.split("_");
char[] ch = redate2[0].toCharArray();
String date3 = ch.toString();
yearss = redate2[0].substring(0, 4);
monss = redate2[0].substring(4, 6);
dayss = redate2[0].substring(6);
String redate = dayss + "/" + dayss + "/" + dayss;
int monthsss=Integer.parseInt(monss);
int daysss=Integer.parseInt(dayss);
monss=monthsss+"";
dayss=daysss+"";
String sql = "SELECT * FROM attendance." + table + "cal WHERE datee='" + dayss
+ "' AND monthh='" + monss + "' AND yearr='" + yearss + "'";
try {
stmt = con.prepareStatement(sql);
rs = stmt.executeQuery();
int totalattendance = 1;
rs.next();
int noo1=rs.getInt("noo");
String sql2 = "SELECT * FROM attendance." + table + "cal WHERE datee='30' AND monthh='03' AND yearr='" + (Integer.parseInt(yearss)+1)+"" + "'";
stmt = con.prepareStatement(sql2);
rs = stmt.executeQuery();
rs.next();
int j = 0;
String sql3 = "SELECT * FROM attendance." + table + "cal WHERE noo >= "+noo1+" and accss=1 ";
stmt = con.prepareStatement(sql3);
rs = stmt.executeQuery();
while (rs.next()) {
String datee=rs.getString("datee");
String monthh=rs.getString("monthh");
String yearrr=rs.getString("yearr");
json.put("name" + j, datee+"-"+monthh+"-"+yearrr);
json.put("branch" + j, rs.getString("content"));
j++;
}
json.put("absent", j + "");
json.put("info", "success");
} catch (JSONException e1) {
try {
json.put("info", "failure");
} catch (JSONException e) {
e.printStackTrace();
}
e1.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
try {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json.toString());
} catch (Exception e) {
System.out.println(e);
}
}
}
Java Code for Request and Response for android application from MYSQL Database Programming Logic and Code with Syntax
package com.sawan;import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
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.JSONException;
import org.json.JSONObject;
/**
* Servlet implementation class AbesentData
*/
@WebServlet("/AbesentData")
public class AbesentData extends HttpServlet {
private static final long serialVersionUID = 1L;
String dayss, monss, yearss;
PreparedStatement stmt = null;
ResultSet rs;
JSONObject json = new JSONObject();
public AbesentData() {
super();
}
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();
String[] paramValues = request.getParameterValues(paramName);
params[i] = paramValues[0];
i++;
}
if (params[1].equals("AbsentStudent")) {
String table = params[0];
table = table.substring(0, 11);
DataBase db = new DataBase();
int clsstrength = 0;
Connection con = db.getConnection();
String date = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
String redate2[] = date.split("_");
char[] ch = redate2[0].toCharArray();
String date3 = ch.toString();
yearss = redate2[0].substring(0, 4);
monss = redate2[0].substring(4, 6);
dayss = redate2[0].substring(6);
String redate = dayss + "/" + dayss + "/" + dayss;
String sql = "SELECT STUDENTNAME FROM attendance." + table + "record WHERE LACTUREDAY='" + dayss
+ "' AND LACTUREMonth='" + monss + "' AND LACTUREyear='" + yearss + "'";
String sql2 = "SELECT STUDENTNAME FROM attendance." + table + "record WHERE LACTUREDAY='" + dayss
+ "' AND LACTUREMonth='" + monss + "' AND LACTUREyear='" + yearss + "' AND LactureVarification=0";
try {
stmt = con.prepareStatement(sql);
rs = stmt.executeQuery();
int totalattendance = 1;
while (rs.next()) {
totalattendance++;
}
stmt = con.prepareStatement(sql2);
rs = stmt.executeQuery();
int j = 0;
while (rs.next()) {
String sql3 = "SELECT STUDENTNAME,STUDENTBRANCH,STUDENTSECTION FROM attendance." + table
+ " WHERE STUDENTROLL='" + rs.getString("STUDENTNAME") + "'";
stmt = con.prepareStatement(sql3);
ResultSet rs3 = stmt.executeQuery();
rs3.next();
json.put("name" + j, rs3.getString("STUDENTNAME"));
json.put("branch" + j, rs3.getInt("STUDENTBRANCH") + "");
json.put("Section" + j, rs3.getString("STUDENTSECTION"));
j++;
}
json.put("absent", j + "");
json.put("totalll", totalattendance + "");
json.put("info", "success");
} catch (JSONException e1) {
try {
json.put("info", "failure");
} catch (JSONException e) {
e.printStackTrace();
}
e1.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
try {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json.toString());
} catch (Exception e) {
}
} else if (params[1].equals("AbsentStudent2")) {
String table = params[0];
table = table.substring(0, 11);
DataBase db = new DataBase();
int clsstrength = 0;
Connection con = db.getConnection();
String date = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
String redate2[] = date.split("_");
char[] ch = redate2[0].toCharArray();
String date3 = ch.toString();
yearss = redate2[0].substring(0, 4);
monss = redate2[0].substring(4, 6);
dayss = redate2[0].substring(6);
String redate = dayss + "/" + dayss + "/" + dayss;
int saw = Integer.parseInt(dayss);
try {
int j = 0;
int totalattendance = 1;
for (int sa = 1; sa <= saw; sa++) {
String sql = "SELECT STUDENTNAME FROM attendance." + table + "record WHERE LACTUREDAY='" + sa
+ "' AND LACTUREMonth='" + monss + "' AND LACTUREyear='" + yearss + "'";
String sql2 = "SELECT STUDENTNAME FROM attendance." + table + "record WHERE LACTUREDAY='" + sa
+ "' AND LACTUREMonth='" + monss + "' AND LACTUREyear='" + yearss
+ "' AND LactureVarification=0";
stmt = con.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
totalattendance++;
}
stmt = con.prepareStatement(sql2);
rs = stmt.executeQuery();
while (rs.next()) {
String sql3 = "SELECT * FROM attendance." + table + " WHERE STUDENTROLL='"
+ rs.getString("STUDENTNAME") + "'";
stmt = con.prepareStatement(sql3);
ResultSet rs3 = stmt.executeQuery();
rs3.next();
json.put("name" + j, rs3.getString("STUDENTNAME"));
json.put("name2" + j, rs3.getString("STUDENTROLL"));
json.put("branch" + j, rs3.getInt("STUDENTBRANCH") + "");
json.put("Section" + j, rs3.getString("STUDENTSECTION"));
json.put("sawan1" + j, 1 + "");
json.put("sawan2" + j, 1 + " ");
json.put("sawan3" + j, 1 + "");
j++;
}
}
json.put("absent", j + "");
json.put("totalll", totalattendance + "");
json.put("info", "success");
} catch (JSONException e1) {
try {
json.put("info", "failure");
} catch (JSONException e) {
e.printStackTrace();
}
e1.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
try {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json.toString());
} catch (Exception e) {
System.out.println(e);
}
}
}
}
No comments:
Post a Comment