老師讓做一個小型的個人財務系統,用這學期學的jsp做。因為項目比較小,所以我用jsp+javabean.
前面分析的都很順利,到後面的時候就出問題了,報了個這樣的錯誤。強行關閉我的tomcat。
- #
- # An unexpected error has been detected by Java Runtime Environment:
- #
- # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c92100b, pid=2360, tid=1300
- #
- # Java VM: Java HotSpot(TM) Client VM (11.3-b02 mixed mode windows-x86)
- # Problematic frame:
- # C [ntdll.dll+0x100b]
- #
- # An error report file with more information is saved as:
- # D:/MyEclipse/Common/plugins/com.genuitec.eclipse.easie.tomcat.myeclipse_8.5.0.me201003121946/tomcat/bin/hs_err_pid2360.log
- #
- # If you would like to submit a bug report, please visit:
- # http://java.sun.com/webapps/bugreport/crash.jsp
- # The crash happened outside the Java Virtual Machine in native code.
- # See problematic frame for where to report the bug.
- #
有關的代碼是這樣的:
1.資料庫操作類
- /**
- * 操作支出表的實體bean
- */
- package com.hb.Dao;
-
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
-
- /**
- * @author icecold
- *
- */
- public class OutDao {
- java.sql.Connection conn = null;
- java.sql.PreparedStatement ps = null;
- java.sql.ResultSet rs = null;
- java.sql.Statement stmt = null;
- String sql = "";
- /*
- * 判斷是否存在重複id
- */
- public boolean isOutExist(String id){
- conn=DatabaseUtil.getConnection();
- String sql="select *from out where id=?";
- try{
- PreparedStatement ps=conn.prepareStatement(sql);
- ps.setString(1, id);
- ResultSet rs=ps.executeQuery();
- if(rs.next()){
- //此id重複
- return true;
- }
- rs.close();
- ps.close();
- }catch(Exception e){
- e.printStackTrace();
- }finally{
- DatabaseUtil.closeConnection(conn);
- }
- return false;
- }
-
- /*
- * 增加記錄
- */
- public boolean insertOut(String id, String name, String type,
- java.sql.Date date, double money, String beizhu) {
- boolean flag = false;
- int n = 0;
- sql = "insert into out values(?,?,?,?,?,?)";
- try {
- ps = conn.prepareStatement(sql);
- ps.setString(1, id);
- ps.setString(2, name);
- ps.setString(3, type);
- ps.setDate(4, date);
- ps.setDouble(5, money);
- ps.setString(6, beizhu);
- n = ps.executeUpdate();
- if (n > 0) {
- flag = true;
- } else {
- flag = false;
- }
- ps.close();
-
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- conn.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- return flag;
- }
-
- }
2、調用Javabean操作資料庫的jsp檔案代碼:
- if (outDao.isOutExist(id)) {
- out.println("<script language='javascript'>alert('此編號已存在,請更換後添加!');</script>");
- } else {
- //if(outDao.insertOut(myOut.getId(),myOut.getName(),myOut.getType(),myOut.getDate(),myOut.getMoney(),myOut.getBeizhu())){
- response.sendRedirect("outMan.jsp");
- //}
-
- }
上面的代碼,我必須按照上面的那樣把那兩行注釋掉,才能不強行關閉我的tomcat,網上搜了下,有人說是資料庫操作的問題,暫時認為這個問題應該出在isOutExist和insertOut兩個之間。
求高手!!!