Tapestry / JDBC - 存储日期

发布于 2024-09-04 08:19:28 字数 7900 浏览 5 评论 0原文

所以我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺孤伤于心 2024-09-11 08:19:28

看起来 ed 为空。

您可以使用调试器来验证这一点,或者在获取日期后添加一些行来测试空值,例如,

Date ed = occasion.getEventDate(); 
if (ed==null) throw new NullPointerException("ed is null");  

如果日期为空,那么您将需要添加一些验证,以便 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.

Date ed = occasion.getEventDate(); 
if (ed==null) throw new NullPointerException("ed is null");  

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 the eventDate property.

一袭水袖舞倾城 2024-09-11 08:19:28

是的,你是对的,ed 为空,但我
无法理解为什么我有
对 Occasion bean 及其的验证
一直都有所需的
注释。

知道了。这与我在 beaneditform 和 tml 文件中的格式有关。不过,感谢您的帮助,如果没有意识到 ed==null 我就找不到它。

Yes your correct, the ed is null but I
cant understand why as I have the
validation on the Occasion bean and it
has always had the Required
annotation.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文