Tapestry / JDBC - 存储日期
所以我使用 Tapestry 并尝试将 beaneditform 中的日期存储到简单的 Access 数据库中。它不起作用,我收到空指针异常,我不明白为什么。
String onSuccess()
{
System.out.println("in on success!");
String nextPage = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection("jdbc:odbc:FYP_Users");
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Date ed = occasion.getEventDate();
String reportDate = df.format(ed);
statement.executeUpdate("INSERT INTO Events (UserName, EventName, EventDate, EventTime, EventDetails, People, Rating) " + "VALUES ('" + login.getUserName() + "', '" + occasion.getEventName()+ "', '" + reportDate + "', '" + occasion.getEventTime() + "', '" + occasion.getEventDetails() + "', '" + occasion.getPeople() + "', '"+ "1" +"')");
connection.close();
occasion = new Occasion();
//occasion.setUserName(occasion.getUserName());
occasion.setEventName(occasion.getEventName());
occasion.setEventDate(occasion.getEventDate());
occasion.setEventTime(occasion.getEventTime());
occasion.setEventDetails(occasion.getEventDetails());
occasion.setPeople(occasion.getPeople());
//occasion.setRating(occasion.getRating());
nextPage = "UserIndex";
}
catch (SQLException e) {e.printStackTrace();}
catch (ClassNotFoundException e) {e.printStackTrace();}
return nextPage;
}
堆栈跟踪
java.util.Calendar.setTime(Unknown Source)
java.text.SimpleDateFormat.format(Unknown Source)
java.text.SimpleDateFormat.format(Unknown Source)
java.text.DateFormat.format(Unknown Source)
myappj.pages.CreateOccasion.onSuccess(CreateOccasion.java:61)
myappj.pages.CreateOccasion.dispatchComponentEvent(CreateOccasion.java)
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:902)
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1081)
org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.triggerContextEvent(InternalComponentResourcesImpl.java:263)
org.apache.tapestry5.corelib.components.Form._$advised$onAction(Form.java:398)
org.apache.tapestry5.corelib.components.Form$onAction$invocation_128ef468876.invokeAdvisedMethod(Form$onAction$invocation_128ef468876.java)
org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:71)
org.apache.tapestry5.ioc.internal.services.LoggingAdvice.advise(LoggingAdvice.java:37)
org.apache.tapestry5.internal.transform.LogWorker$1.advise(LogWorker.java:54)
org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:80)
org.apache.tapestry5.corelib.components.Form.onAction(Form.java)
org.apache.tapestry5.corelib.components.Form.dispatchComponentEvent(Form.java)
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:910)
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1081)
org.apache.tapestry5.internal.services.ComponentEventRequestHandlerImpl.handle(ComponentEventRequestHandlerImpl.java:75)
org.apache.tapestry5.internal.services.ImmediateActionRenderResponseFilter.handle(ImmediateActionRenderResponseFilter.java:42)
$ComponentEventRequestHandler_128ef45bf4a.handle($ComponentEventRequestHandler_128ef45bf4a.java)
org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42)
$ComponentEventRequestHandler_128ef45bf4a.handle($ComponentEventRequestHandler_128ef45bf4a.java)
org.apache.tapestry5.services.TapestryModule$36.handle(TapestryModule.java:2164)
$ComponentEventRequestHandler_128ef45bf4a.handle($ComponentEventRequestHandler_128ef45bf4a.java)
$ComponentEventRequestHandler_128ef45bea5.handle($ComponentEventRequestHandler_128ef45bea5.java)
org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handleComponentEvent(ComponentRequestHandlerTerminator.java:43)
$ComponentRequestHandler_128ef45be99.handleComponentEvent($ComponentRequestHandler_128ef45be99.java)
org.apache.tapestry5.internal.services.ComponentEventDispatcher.dispatch(ComponentEventDispatcher.java:46)
$Dispatcher_128ef45be9b.dispatch($Dispatcher_128ef45be9b.java)
$Dispatcher_128ef45be92.dispatch($Dispatcher_128ef45be92.java)
org.apache.tapestry5.services.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:245)
org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26)
$RequestHandler_128ef45be93.service($RequestHandler_128ef45be93.java)
org.apache.tapestry5.services.TapestryModule$4.service(TapestryModule.java:778)
$RequestHandler_128ef45be93.service($RequestHandler_128ef45be93.java)
org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:767)
$RequestHandler_128ef45be93.service($RequestHandler_128ef45be93.java)
org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:85)
$RequestHandler_128ef45be93.service($RequestHandler_128ef45be93.java)
myappj.services.AppModule$1.service(AppModule.java:90)
$RequestFilter_128ef45be8e.service($RequestFilter_128ef45be8e.java)
$RequestHandler_128ef45be93.service($RequestHandler_128ef45be93.java)
org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:90)
org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:81)
org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:85)
org.apache.tapestry5.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:103)
$RequestHandler_128ef45be93.service($RequestHandler_128ef45be93.java)
$RequestHandler_128ef45be88.service($RequestHandler_128ef45be88.java)
org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:197)
org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53)
$HttpServletRequestHandler_128ef45be8a.service($HttpServletRequestHandler_128ef45be8a.java)
org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
$HttpServletRequestFilter_128ef45be87.service($HttpServletRequestFilter_128ef45be87.java)
$HttpServletRequestHandler_128ef45be8a.service($HttpServletRequestHandler_128ef45be8a.java)
org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:726)
$HttpServletRequestHandler_128ef45be8a.service($HttpServletRequestHandler_128ef45be8a.java)
$HttpServletRequestHandler_128ef45be85.service($HttpServletRequestHandler_128ef45be85.java)
org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:127)
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:722)
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:404)
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
org.mortbay.jetty.Server.handle(Server.java:324)
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:842)
org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:648)
org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)
So Im using Tapestry and trying to store a date from a beaneditform into a simple Access database. It wont work, Im getting Null pointer exceptions and I cannot understand why.
String onSuccess()
{
System.out.println("in on success!");
String nextPage = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection("jdbc:odbc:FYP_Users");
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Date ed = occasion.getEventDate();
String reportDate = df.format(ed);
statement.executeUpdate("INSERT INTO Events (UserName, EventName, EventDate, EventTime, EventDetails, People, Rating) " + "VALUES ('" + login.getUserName() + "', '" + occasion.getEventName()+ "', '" + reportDate + "', '" + occasion.getEventTime() + "', '" + occasion.getEventDetails() + "', '" + occasion.getPeople() + "', '"+ "1" +"')");
connection.close();
occasion = new Occasion();
//occasion.setUserName(occasion.getUserName());
occasion.setEventName(occasion.getEventName());
occasion.setEventDate(occasion.getEventDate());
occasion.setEventTime(occasion.getEventTime());
occasion.setEventDetails(occasion.getEventDetails());
occasion.setPeople(occasion.getPeople());
//occasion.setRating(occasion.getRating());
nextPage = "UserIndex";
}
catch (SQLException e) {e.printStackTrace();}
catch (ClassNotFoundException e) {e.printStackTrace();}
return nextPage;
}
Stack trace
java.util.Calendar.setTime(Unknown Source)
java.text.SimpleDateFormat.format(Unknown Source)
java.text.SimpleDateFormat.format(Unknown Source)
java.text.DateFormat.format(Unknown Source)
myappj.pages.CreateOccasion.onSuccess(CreateOccasion.java:61)
myappj.pages.CreateOccasion.dispatchComponentEvent(CreateOccasion.java)
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:902)
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1081)
org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.triggerContextEvent(InternalComponentResourcesImpl.java:263)
org.apache.tapestry5.corelib.components.Form._$advised$onAction(Form.java:398)
org.apache.tapestry5.corelib.components.Form$onAction$invocation_128ef468876.invokeAdvisedMethod(Form$onAction$invocation_128ef468876.java)
org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:71)
org.apache.tapestry5.ioc.internal.services.LoggingAdvice.advise(LoggingAdvice.java:37)
org.apache.tapestry5.internal.transform.LogWorker$1.advise(LogWorker.java:54)
org.apache.tapestry5.internal.services.AbstractComponentMethodInvocation.proceed(AbstractComponentMethodInvocation.java:80)
org.apache.tapestry5.corelib.components.Form.onAction(Form.java)
org.apache.tapestry5.corelib.components.Form.dispatchComponentEvent(Form.java)
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:910)
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1081)
org.apache.tapestry5.internal.services.ComponentEventRequestHandlerImpl.handle(ComponentEventRequestHandlerImpl.java:75)
org.apache.tapestry5.internal.services.ImmediateActionRenderResponseFilter.handle(ImmediateActionRenderResponseFilter.java:42)
$ComponentEventRequestHandler_128ef45bf4a.handle($ComponentEventRequestHandler_128ef45bf4a.java)
org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42)
$ComponentEventRequestHandler_128ef45bf4a.handle($ComponentEventRequestHandler_128ef45bf4a.java)
org.apache.tapestry5.services.TapestryModule$36.handle(TapestryModule.java:2164)
$ComponentEventRequestHandler_128ef45bf4a.handle($ComponentEventRequestHandler_128ef45bf4a.java)
$ComponentEventRequestHandler_128ef45bea5.handle($ComponentEventRequestHandler_128ef45bea5.java)
org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handleComponentEvent(ComponentRequestHandlerTerminator.java:43)
$ComponentRequestHandler_128ef45be99.handleComponentEvent($ComponentRequestHandler_128ef45be99.java)
org.apache.tapestry5.internal.services.ComponentEventDispatcher.dispatch(ComponentEventDispatcher.java:46)
$Dispatcher_128ef45be9b.dispatch($Dispatcher_128ef45be9b.java)
$Dispatcher_128ef45be92.dispatch($Dispatcher_128ef45be92.java)
org.apache.tapestry5.services.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:245)
org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26)
$RequestHandler_128ef45be93.service($RequestHandler_128ef45be93.java)
org.apache.tapestry5.services.TapestryModule$4.service(TapestryModule.java:778)
$RequestHandler_128ef45be93.service($RequestHandler_128ef45be93.java)
org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:767)
$RequestHandler_128ef45be93.service($RequestHandler_128ef45be93.java)
org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:85)
$RequestHandler_128ef45be93.service($RequestHandler_128ef45be93.java)
myappj.services.AppModule$1.service(AppModule.java:90)
$RequestFilter_128ef45be8e.service($RequestFilter_128ef45be8e.java)
$RequestHandler_128ef45be93.service($RequestHandler_128ef45be93.java)
org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:90)
org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:81)
org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:85)
org.apache.tapestry5.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:103)
$RequestHandler_128ef45be93.service($RequestHandler_128ef45be93.java)
$RequestHandler_128ef45be88.service($RequestHandler_128ef45be88.java)
org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:197)
org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53)
$HttpServletRequestHandler_128ef45be8a.service($HttpServletRequestHandler_128ef45be8a.java)
org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
$HttpServletRequestFilter_128ef45be87.service($HttpServletRequestFilter_128ef45be87.java)
$HttpServletRequestHandler_128ef45be8a.service($HttpServletRequestHandler_128ef45be8a.java)
org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:726)
$HttpServletRequestHandler_128ef45be8a.service($HttpServletRequestHandler_128ef45be8a.java)
$HttpServletRequestHandler_128ef45be85.service($HttpServletRequestHandler_128ef45be85.java)
org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:127)
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:722)
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:404)
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
org.mortbay.jetty.Server.handle(Server.java:324)
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:842)
org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:648)
org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来
ed
为空。您可以使用调试器来验证这一点,或者在获取日期后添加一些行来测试空值,例如,
如果日期为空,那么您将需要添加一些验证,以便 Tapestry 不允许空日期。请参阅 Tapestry 5.1 网站上的表单输入验证。例如,在您的
Occasion
bean 中,向eventDate
属性添加@Validate("required")
注释。It looks like
ed
is null.You can either use a debugger to verify this, or add some lines after getting the date to test for null, e.g.
If the date is null, then you will need to add some validation so that tapestry doesn't allow the null date. See Form Input Validation on the Tapestry 5.1 website. For example, in your
Occasion
bean add a@Validate("required")
annotation to theeventDate
property.知道了。这与我在 beaneditform 和 tml 文件中的格式有关。不过,感谢您的帮助,如果没有意识到 ed==null 我就找不到它。
Got it. It was to do with my formatting in the beaneditform and tml file. Thanks for the help though, without realising ed==null I would not have found it.