方法页面:public void update2(newsjava news) throws Exception {
String sql = "UPDATE insertnews SET news_title=?,news_time=?,news_content=? where news_id=?" ;
PreparedStatement pstmt = null ;
db jdbc = null ;
// 下面是针对数据库的具体操作
try
{
// 连接数据库
jdbc = new db() ;
pstmt = jdbc.getConnection().prepareStatement(sql) ;
pstmt.setString(1,news.getNews_id()) ;
pstmt.setString(2,news.getNews_title()) ;
pstmt.setString(3,news.getNews_time()) ;
pstmt.setString(4,news.getNews_content()) ;
// 进行数据库更新操作
pstmt.executeUpdate() ;
pstmt.close() ;
}
catch (Exception e)
{
throw new Exception("更新数据库操作出现异常") ;
}
}更新页面:
 <%
   newsjava news=new newsjava();
   newsFactory F=new newsFactory();
   SimpleDateFormat   df=new   SimpleDateFormat( "yyyyMMdd HH:mm:ss "); 
   String time=df.format(new   Date()); 
   String id3=request.getParameter("id");
   String title3=request.getParameter("title");
   String content3=request.getParameter("content");
   news.setNews_id(id3);
   news.setNews_title(title3);
   news.setNews_content(content3);
   news.setNews_time(time);
   F.getDAO().update2(news);
   out.println("修改成功编号为"+id3+"的新闻                                ");
   out.println("修改成功标题为"+title3+"的新闻"+time); %>
错误:这句无法执行 F.getDAO().update2(news);
求解

解决方案 »

  1.   

    type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.Exception: 更新数据库操作出现异常
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:541)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    root cause javax.servlet.ServletException: java.lang.Exception: 更新数据库操作出现异常
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
    org.apache.jsp.admin_005fupdatesuccess_jsp._jspService(admin_005fupdatesuccess_jsp.java:96)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    root cause java.lang.Exception: 更新数据库操作出现异常
    newsbd.dbaction.update2(dbaction.java:286)
    org.apache.jsp.admin_005fupdatesuccess_jsp._jspService(admin_005fupdatesuccess_jsp.java:82)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.
      

  2.   

    String sql = "UPDATE insertnews SET news_id=?,news_title=?,news_time=?,news_content=? where news_id=?" ;
    使用这条语句出现上面错误
      

  3.   

    你的参数给的有问题吧?
    "UPDATE insertnews SET news_title=?,news_time=?,news_content=? where news_id=?"pstmt.setString(1,news.getNews_id()) ;
    pstmt.setString(2,news.getNews_title()) ;
    pstmt.setString(3,news.getNews_time()) ;
    pstmt.setString(4,news.getNews_content()) ;第一个要title,你给id?第二个要news_time,你给title?
      

  4.   

    dao里的异常不要处理 成 throw new Exception("更新数据库操作出现异常")
    直接用 e.printStackTrace();
    看看什么异常。
      

  5.   

    如果将
    String sql = "UPDATE insertnews SET news_id=?,news_title=?,news_time=?,news_content=? where news_id=?" ;
    换成
    tring sql = "UPDATE insertnews SET news_title=?,news_time=?,news_content=? where news_id=?" ;
    就是去的news_id这项 程序不报错 但是无法更新 还是原来的数据
      

  6.   

    给参的时候改改就行了:pstmt.setString(1,news.getNews_title()) ;
    pstmt.setString(2,news.getNews_time()) ;
    pstmt.setString(3,news.getNews_content()) ;
    pstmt.setString(4,news.getNews_id()) ;
      

  7.   

    dao里的异常不要处理 成 throw new Exception("更新数据库操作出现异常")。
    直接用 e.printStackTrace();
    看看什么异常。
      

  8.   


    可能是你的new_id=?的?这个值没有在出现在数据库里
      

  9.   

     No value specified for parameter 5
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
    at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2176)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1993)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922)
    at newsbd.dbaction.update2(dbaction.java:281)
    at org.apache.jsp.admin_005fupdatesuccess_jsp._jspService(admin_005fupdatesuccess_jsp.java:82)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    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:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)
      

  10.   

    No value specified for parameter 5
      

  11.   

    汗。你的赋值错误。你数据库哪个字段是lang型的。
      

  12.   

    不是说了嘛,第五个参数没有指定值:
    String sql = "UPDATE insertnews SET news_id=?,news_title=?,news_time=?,news_content=? where news_id=?" ;pstmt.setString(1,news.getNews_id()) 
    pstmt.setString(2,news.getNews_title()) ;
    pstmt.setString(3,news.getNews_time()) ;
    pstmt.setString(4,news.getNews_content()) ;
    pstmt.setString(5,news.getNews_id()) ;