Java 如何使用servlet从数据库中获取日期并将其放入fullcalendar中
我是第一次在我的应用程序中使用fullcalendar。我只是尝试将所有事件从DB放置到fullcalendar。以下是我尝试的代码Java 如何使用servlet从数据库中获取日期并将其放入fullcalendar中,java,servlets,fullcalendar,Java,Servlets,Fullcalendar,我是第一次在我的应用程序中使用fullcalendar。我只是尝试将所有事件从DB放置到fullcalendar。以下是我尝试的代码 MyJsp.jsp $('#calendar').fullCalendar({ //defaultDate: '2015-02-12', editable: true, events: "/FullcalendarProject/FullCalenda
MyJsp.jsp
$('#calendar').fullCalendar({
//defaultDate: '2015-02-12',
editable: true,
events: "/FullcalendarProject/FullCalendarChecking"
});
FullCalendarChecking.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List l = new ArrayList();
PreparedStatement st = null;
ResultSet rst = null;
Connection con = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/raptor1_5","root","");
String query="select * from tblplanner where User_id=?";
st = con.prepareStatement(query);
st.setString(1, "112");
rst =st.executeQuery();
while(rst.next())
{
System.out.println("entered...");
String plannedDate =rst.getString("date"); // this will be start in fullcalendar
String plannedChapter =rst.getString("chapter"); // this will be title in fullcalendar
l.add(plannedDate);
l.add(plannedChapter);
//here i am doing woring..?!!
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try{
con.close();
rst.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
out.write(new Gson().toJson(l));
}
但是这段代码并不像我期望的那样工作
输出:
预期产出:
我的表格:
用户id章节日期
112第1章2015-04-27
112第2章2015-04-29
112第3章2015-04-30
如何执行此操作?请共享正在获取的数组。@Franky我获取的数组[2015-04-09,Plants,2015-04-10,Plants,2015-04-12,Plants2,2015-04-13,Plants3,2015-04-08,Plants4,2015-04-12,Animals]您的数组不正确,应该是这样的[{标题:'Event1',开始:'2011-04-04'},{title:'event2',start:'2010-01-05',end:'2010-01-07'}]你是对的,但我不知道如何从db实现这样的目标[{title:'Event1',start:'2011-04-04'},{title:'event2',start:'2010-01-05',end:'2010-01-07'}],给我一个样本code@Franky我有数据库中的数据,只有用户id,章节和日期,所以我怎么能这样形成[{title:'chaptername',start:'2011-04-04'},{title:'chapter2',start:'2010-01-05',},{title:'chpater3',start:'2010-01-07'}]。
all fetched dates dsiaplays in todays date
all fetched dates show in its own date