无法插入到mysql中

时间:2016-12-01 19:52:34

标签: java mysql nullpointerexception

    String registeritQuery= "INSERT INTO explorer.usr_itinerary(itinerary_desc, latd, longd, owner_id, creation_date, visited_date,it_grp_name" + "VALUES (?,?,?,?,?,?,?)";

    PreparedStatement pst = conn.prepareStatement(registeritQuery);

    pst.setString(1,it_Desc);
    pst.setBigDecimal(2,new BigDecimal(latd));
    pst.setBigDecimal(3,new BigDecimal(longd));
    pst.setInt(4,userid);
    pst.setDate(5, new java.sql.Date(System.currentTimeMillis()));
    pst.setDate(6,java.sql.Date.valueOf(visitdate));
    pst.setString(7,Integer.toString(n));
    cnt = pst.executeUpdate();

表格列:

    id(auto_increment)- int
    itinerary_desc  - varchar
    latd - decimal - (9,6)
    longd- decimal - (9,6)
    creation_date - date
    visited_date - date
    it_grp_name - varchar

我在prepareStatement之前获取了所有值,但它没有插入记录。

错误:

java.lang.NullPointerException
    at explorer.MySQLDataStoreUtilities.insertItinerary(MySQLDataStoreUtilities.java:182)
    at org.apache.jsp.insertItinerary_jsp._jspService(insertItinerary_jsp.java:122)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:2)

您的查询应该是这样的:

String registeritQuery= "INSERT INTO explorer.usr_itinerary(itinerary_desc, latd, longd, owner_id, creation_date, visited_date,it_grp_name) VALUES (?,?,?,?,?,?,?)";
你错过了) and space 您的查询就像it_grp_name"+"VALUES这意味着it_grp_nameVALUES

因此您应该将其替换为it_grp_name)"+" VALUES这意味着it_grp_name) VALUES