Search the Blog

Saturday, July 27, 2019

JAVA Code Academic Calendar with Server Response and SQL Update with admin delete authority

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

Translate