package com.schedulers;
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.Date;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import DBConnection.DBConnect;
public class P6UserInsertScheduleServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public P6UserInsertScheduleServlet() {
super();
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
}
@SuppressWarnings("unused")
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Connection conn = null;
conn = DBConnect.getConnection();
PreparedStatement st = null;
String[] checked = request.getParameterValues("primTC");
String submit = request.getParameter("submit");
System.out.println("**********");
System.out.println(submit);
@SuppressWarnings("unused")
ResultSet rs = null;
String ids = null;
@SuppressWarnings("unused")
Statement statement = null;
String s_description = "Schedule_";
String runDate = null;
SimpleDateFormat monthDayYearformatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
//SimpleDateFormat monthDayYearformatter = new SimpleDateFormat("DD-MM-YYYY HH:MI:SS");
Date date = new Date();
runDate = monthDayYearformatter.format(date);
System.out.println(runDate);
String s_tasks = "1,2";
String s_status = "R";
String s_userschedule = "y";
int insertQuery = 0;
int j = 0;
try {
if (submit.equals("Sync")) {
for (String string : checked) {
try {
@SuppressWarnings("unused")
int id = Integer.parseInt(string);
statement = conn.createStatement();
String QueryString = "insert into SCHEDULE(DESCRIPTION,RUN_DATE,TASKS,STATUS,USER_SCHEDULED) values (CONCAT('"+ s_description+ "',(select max(IK)+1 from schedule)),to_date('"+runDate+"','DD-MM-YYYY HH:MI:SS'),'"+ s_tasks+ "','"+ s_status+ "','"+ s_userschedule + "')";
System.out.print(QueryString);
st = conn.prepareStatement(QueryString);
System.out.print(insertQuery);
st.execute();
System.out.println(j);
if (j == 0) {
ids = string;
} else {
ids += "," + string;
}
j++;
System.out.print(ids);
conn.setAutoCommit(true);
} catch (Exception e) {
e.printStackTrace();
}
}
if (!ids.isEmpty()) {
String QueryString = "UPDATE PROJECT_STAGE SET ACTIVE = 0 WHERE IK NOT IN ("
+ ids + ")";
st = conn.prepareStatement(QueryString);
st.execute();
}
}
if (submit.equals("Sync Later")) {
String syncdate = request.getParameter("syncdate");
for (String string : checked) {
try {
int id = Integer.parseInt(string);
statement = conn.createStatement();
String QueryString = "insert into SCHEDULE (DESCRIPTION,RUN_DATE,TASKS,STATUS,USER_SCHEDULED) values (CONCAT('"+ s_description+ "',(select max(IK)+1 from schedule)), to_date('"+runDate+"','DD-MM-YYYY HH:MI:SS'),'"+ s_tasks+ "','"+ s_status+ "','"+ s_userschedule + "')";
System.out.print(QueryString);
st = conn.prepareStatement(QueryString);
System.out.print(insertQuery);
st.execute();
System.out.println(j);
if (j == 0) {
ids = string;
} else {
ids += "," + string;
}
j++;
System.out.print(ids);
conn.setAutoCommit(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
String forward = "/user/index.jsp";
RequestDispatcher rd = request.getRequestDispatcher(forward);
rd.include(request, response);
}
}
error:
java.lang.NullPointerException
at java.util.Calendar.setTime(Unknown Source)
at java.text.SimpleDateFormat.format(Unknown Source)
at java.text.SimpleDateFormat.format(Unknown Source)
at java.text.DateFormat.format(Unknown Source)
at com.schedulers.UserScheduleExe.ScheduleExes(UserScheduleExe.java:30)
at org.apache.jsp.user.schedule_jsp._jspService(schedule_jsp.java:120)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)