如何在jsp中使用oracle作为后端和dhtmlx事件日历加载数据

时间:2014-01-06 07:37:30

标签: jsp oracle11g dhtmlx-scheduler

需要解决方案,我已按照链接中指定的所有步骤操作 http://blog.javaplanner.com/creating-a-simple-java-event-calendar

我更改了它在Oracle中支持的dataformat的EventsManager.java代码

package com.dhtmlx.demo;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.dhtmlx.planner.DHXEv;
import com.dhtmlx.planner.DHXEvent;
import com.dhtmlx.planner.DHXEventsManager;
import com.dhtmlx.planner.DHXStatus;
import java.sql.*;

public class EventsManager extends DHXEventsManager {

        public EventsManager(HttpServletRequest request) {
                        super(request);
        }

        public Iterable getEvents() {
                        DHXEventsManager.date_format = "YYYY-MM-DD HH24:MI:SS.FF";
                        List evs = new ArrayList();
                        try {
                                        java.sql.Connection conn = DatabaseConnection.getConnection();
                java.sql.Statement statement = conn.createStatement();

                String query = "SELECT event_id, event_name, start_date, end_date FROM events";
                ResultSet resultset = statement.executeQuery(query);

                while (resultset.next()) {
                DHXEvent e = new DHXEvent();
                e.setId(Integer.parseInt(resultset.getString("event_id")));
                   e.setText(resultset.getString("event_name"));
                   e.setStart_date(resultset.getString("start_date"));
                   e.setEnd_date(resultset.getString("end_date"));
                evs.add(e);
                }
                conn.close();
                        } catch (SQLException e1) {
                                        e1.printStackTrace();
                        }
                        DHXEventsManager.date_format = "YYYY-MM-DD HH24:MI:SS.FF";

                        return evs;
        }

        @Override
        public DHXStatus saveEvent(DHXEv event, DHXStatus status) {
                        java.sql.Connection conn = DatabaseConnection.getConnection();
                        java.sql.PreparedStatement ps = null;
                        java.sql.ResultSet result = null;
                        try {
                                        String query = null;
                                        String start_date = new SimpleDateFormat("YYYY-MM-DD HH24:MI:SS.FF").format(event.getStart_date());
                                        String end_date = new SimpleDateFormat("YYYY-MM-DD HH24:MI:SS.FF").format(event.getEnd_date());
                                        if (status == DHXStatus.UPDATE) {
                                                    query = "UPDATE events SET event_name=?, start_date=?, end_date=? WHERE event_id=?";
                                                    ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
                                                    ps.setString(1, event.getText());
                                                    ps.setString(2, start_date);
                                                    ps.setString(3, end_date);
                                                    ps.setInt(4, event.getId());

                                        } else if (status == DHXStatus.INSERT) {
                                                    query = "INSERT INTO events (event_id, event_name, start_date, end_date) VALUES (null, ?, ?, ?)";
                                                    ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
                                                    ps.setString(1, event.getText());
                                                    ps.setString(2, start_date);
                                                    ps.setString(3, end_date);

                                        } else if (status == DHXStatus.DELETE) {
                                                    query = "DELETE FROM events WHERE event_id=? LIMIT 1";
                                                    ps = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
                                                    ps.setInt(1, event.getId());
                                        }

                                        if (ps!=null) {
                                                    ps.executeUpdate();
                                                    result = ps.getGeneratedKeys();
                                                    if (result.next()) {
                                                                    event.setId(result.getInt(1));
                                                    }
                                        }

                        } catch (SQLException e) {
                                        e.printStackTrace();
                        } finally {
                if (result != null) try { result.close(); } catch (SQLException e) {}
                if (ps != null) try { ps.close(); } catch (SQLException e) {}
                if (conn != null) try { conn.close(); } catch (SQLException e) {}
            }

                        return status;
        }

        @Override
        public DHXEv createEvent(String id, DHXStatus status) {
                        return new DHXEvent();
        }
}

但是在控制台上遇到错误

java.lang.IllegalArgumentException: Illegal pattern character 'I'
at java.text.SimpleDateFormat.compile(Unknown Source)
at java.text.SimpleDateFormat.initialize(Unknown Source)
at java.text.SimpleDateFormat.<init>(Unknown Source)
at java.text.SimpleDateFormat.<init>(Unknown Source)
at com.dhtmlx.planner.DHXEvent.setStart_date(DHXEvent.java:61)
at com.dhtmlx.demo.EventsManager.getEvents(EventsManager.java:36)
at com.dhtmlx.planner.DHXEventsManager.load(DHXEventsManager.java:49)
at com.dhtmlx.planner.DHXEventsManager.run(DHXEventsManager.java:42)
at org.apache.jsp.events_jsp.getEvents(events_jsp.java:15)
at org.apache.jsp.events_jsp._jspService(events_jsp.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at     org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)

并且无法显示从日历中的数据库中挑选的那些事件

能够在浏览器上创建这些事件但是没有得到保存并抛出错误parseException

0 个答案:

没有答案