一个错误HTTP Status 500 - 请大家帮忙分析分析
HTTP Status 500 ---------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.lang.IllegalArgumentException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.IllegalArgumentException
java.sql.Date.valueOf(Unknown Source)
com.dao.BorrowDAO.insertBorrow(BorrowDAO.java:36)
com.action.Borrow.bookborrow(Borrow.java:122)
com.action.Borrow.execute(Borrow.java:30)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.32 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.32
主要原因是不是java.sql.Date.valueOf(Unknown Source)????
--------------------编程问答-------------------- 对,楼主在看一下值。调试一下 --------------------编程问答-------------------- java.sql.Date.valueOf(Unknown Source)
com.dao.BorrowDAO.insertBorrow(BorrowDAO.java:36)
com.action.Borrow.bookborrow(Borrow.java:122)
com.action.Borrow.execute(Borrow.java:30)
Lz这个几个是关键。。。 --------------------编程问答-------------------- java.sql.Date.valueOf(Unknown Source)
com.dao.BorrowDAO.insertBorrow(BorrowDAO.java:36)
com.action.Borrow.bookborrow(Borrow.java:122)
com.action.Borrow.execute(Borrow.java:30)
Lz这个几个是关键。。。 --------------------编程问答-------------------- java.lang.IllegalArgumentException
非法参数
java.lang.IllegalArgumentException
java.sql.Date.valueOf(Unknown Source)
com.dao.BorrowDAO.insertBorrow(BorrowDAO.java:36)
看看你的DAO的36行。 --------------------编程问答-------------------- 类型转化错误 --------------------编程问答-------------------- IllegalArgumentException 类型转换错误,你跟代码调试下 --------------------编程问答-------------------- +1 --------------------编程问答-------------------- public int insertBorrow(ReaderForm readerForm,BookForm bookForm,String operator){
//获取系统日期
Date dateU=new Date();
java.sql.Date date=new java.sql.Date(dateU.getTime());
String sql1="select t.days from tb_bookinfo b left join tb_booktype t on b.typeid=t.id where b.id="+bookForm.getId()+"";
ResultSet rs=conn.executeQuery(sql1);
int days=0;
try {
if (rs.next()) {
days = rs.getInt(1);
}
} catch (SQLException ex) {
}
//计算归还时间
String date_str=String.valueOf(date);
String dd = date_str.substring(8,10);
String DD = date_str.substring(0,8)+String.valueOf(Integer.parseInt(dd) + days);
java.sql.Date backTime= java.sql.Date.valueOf(DD);
String sql ="Insert into tb_borrow (readerid,bookid,borrowTime,backTime,operator) values("+readerForm.getId()+","+bookForm.getId()+",'"+date+"','"+backTime+"','"+operator+"')";
int falg = conn.executeUpdate(sql);
System.out.println("添加图书借阅信息的SQL:" + sql);
conn.close();
return falg;
}
以上是BorrowDAO的对应代码,哪里出了问题,请大家多多指点,我刚学习不久,谢谢了 --------------------编程问答-------------------- 后来这个问题是怎么解决了的呢? --------------------编程问答-------------------- 给你几点调试的注意事项:
1.java.sql.Date date=new java.sql.Date(dateU.getTime());
2. days = rs.getInt(1);
3.String date_str=String.valueOf(date);
4.String DD = date_str.substring(0,8)+String.valueOf(Integer.parseInt(dd) + days);
java.sql.Date backTime= java.sql.Date.valueOf(DD);
我觉得应该是你的数据类型转换异常一起的,你试试导入util下面的日期类看看!
--------------------编程问答-------------------- com.dao.BorrowDAO.insertBorrow(BorrowDAO.java:36)
看一下这个类的36行就可以了 --------------------编程问答-------------------- java.lang.IllegalArgumentException
非法参数
java.lang.IllegalArgumentException
java.sql.Date.valueOf(Unknown Source)
com.dao.BorrowDAO.insertBorrow(BorrowDAO.java:36)
看看你的DAO的36行。
补充:Java , Web 开发