Java.sql.SQLException:ORA-00604

时间:2014-10-13 10:00:37

标签: java oracle servlets jdbc

我使用jsp和servlet开发了一个网站,但它提供了异常 java.sql.SQLException:ORA-00604.重新启动服务器后它运行正常。 以下是我的代码

public class LoginCheck extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginCheck() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        ArrayList<String> appAddList = new ArrayList<String>();
        ArrayList<String> appNameList = new ArrayList<String>();

        PrintWriter out = response.getWriter();

        Calendar objCal1=Calendar.getInstance();
        Calendar objCal2=Calendar.getInstance();
        objCal2.set(1970,0,1,0,0,0);
        response.setDateHeader("Last-Modified",objCal1.getTime().getTime());
        response.setDateHeader("Expires",objCal2.getTime().getTime());
        response.setHeader( "Pragma" , "no-cache" );
        response.setHeader( "Cache-Control" , "no-cache" );
        response.addHeader("Cache-Control","no-store");


        Cookie cookies[] = request.getCookies();
        if(cookies != null) {
            for(int i = 0; i < cookies.length; i++) {
                cookies[i].setMaxAge(0);
                response.addCookie(cookies[i]);
            }
        }




        HttpSession session = request.getSession();
        session.setAttribute( "user" , request.getParameter( "username" ) );
        session.setAttribute( "pass" , request.getParameter( "pass" ) );
        String user = (String)session.getAttribute( "user" );
        String pass = (String)session.getAttribute( "pass" );
        session.setMaxInactiveInterval(120);

        java.sql.Connection con = TSM.intf.Common.com.Common.Connection.getConnection();
        Statement stmtEmpTable = null;
        Statement stmtAppTable = null;
        PreparedStatement stmtDesigID = null;
        PreparedStatement stmtEmpTableAppAcc = null;

        try {
            stmtEmpTable = con.createStatement();
            stmtAppTable = con.createStatement();

            stmtEmpTableAppAcc = con.prepareStatement( "select appaccess from employee where empid = ?" );
            stmtDesigID = con.prepareStatement( "select desigid from employee where empid = ?" );

            ResultSet rsEmp = stmtEmpTable.executeQuery( "Select empid , username , userpassword , employeename from Employee" );
            ResultSet rsAppName = stmtAppTable.executeQuery( "select appname from application" );

            boolean correctId = false;

            boolean mach = false;

            int indexnum = Integer.parseInt( request.getParameter("index") );

            String[] appaccess =  null;

            String path = response.encodeURL(request.getContextPath() );

            appAddList.add( 0 , path + "\\JSP\\Login\\index.jsp");
            appNameList.add( 0 , "index" );

            while( rsEmp.next() ) {
                if( user.equals( rsEmp.getString("username") ) && pass.equals( rsEmp.getString("userpassword") ) ) {
                    correctId = true;

                    String name = rsEmp.getString("employeename");
                    String[] empName = name.split(" ");
                    String emp = "";
                    for(String str : empName) {
                        if( str.length() != 0 ) {
                            str = str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase() + " ";
                            emp += str;
                        }
                    }

                    session.setAttribute( "empname" , emp );
                    session.setAttribute( "empid" , rsEmp.getInt("empid") );

                    stmtEmpTableAppAcc.setInt( 1 , (Integer)session.getAttribute("empid") );
                    ResultSet rs = stmtEmpTableAppAcc.executeQuery();

                    rs.next();
                    appaccess = rs.getString("appaccess").split("#~##~#");

                    while( rsAppName.next() ) {
                        appAddList.add( path + "\\JSP\\Login\\" + rsAppName.getString("appname") + "Home.jsp" );
                        appNameList.add( rsAppName.getString("appname") );
                    }

                    stmtDesigID.setInt( 1 , (Integer)session.getAttribute("empid") );
                    ResultSet rsdesgid = stmtDesigID.executeQuery();
                    rsdesgid.next();
                    if( rsdesgid.getInt(1) == 1) {
                        appAddList.set( 1 , path + "\\JSP\\Login\\TimeManagerHome.jsp" );
                    }

                    for( String str : appaccess ) {
                        if( indexnum == 0) {
                            mach = true;
                            out.println("<html><HEAD><meta http-equiv=\"refresh\" content=\"0;URL=" + appAddList.get(indexnum) + "\"></HEAD>");
                            out.println("<body></body></html>");
                        }
                        if( str.equals( appNameList.get(indexnum) ) ) {
                            mach = true;
                            out.println("<html><HEAD><meta http-equiv=\"refresh\" content=\"0;URL=" + appAddList.get(indexnum) + "\"></HEAD>");
                            out.println("<body></body></html>");
                        }
                    }
                    rs.close();
                    rsdesgid.close();
                }
            }

            String url = response.encodeURL(request.getContextPath() + "\\JSP\\Login\\Login.jsp");

            if( !correctId ) {
                out.print( "<script>alert(\"Please Enter Correct UserID & Password.\")</script>" );
                out.println("<html><HEAD><meta http-equiv=\"refresh\" content=\"0;URL=" + url + "\"></HEAD>");
                out.println("<body></body></html>");
            }

            if( !mach && correctId) {
                out.print( "<script>alert(\"Do not use the application.\")</script>" );
                out.println("<html><HEAD><meta http-equiv=\"refresh\" content=\"0;URL=" + url + "\"></HEAD>");
                out.println("<body></body></html>");
            }

            rsEmp.close();
            rsAppName.close();

        } catch( SQLException e ) {
            e.printStackTrace();
        }           
    }    
}

3 个答案:

答案 0 :(得分:0)

我可以看到你已经打开了几个陈述和准备好的陈述

stmtEmpTable = con.createStatement(); 
stmtAppTable = con.createStatement(); 
stmtEmpTableAppAcc = con.prepareStatement( "select appaccess from employee where empid = ?" ); 
stmtDesigID = con.prepareStatement("select ...");

但是我无法在 finally {} 块中看到你正确关闭。 我相信这是你获得 java.sql.SQLException:ORA-00604。

的地方

请在finally{}块内关闭它们,并检查是否收到相同的异常错误。保持这是一个很好的做法。

希望这可以帮助您克服这个问题。

答案 1 :(得分:0)

您尚未关闭为sql连接建立的connection对象。建议关闭所有语句,结果集和连接对象。

finally{
resultset.close();
statement.close();
connection.close();
}
即使出现错误,

finally块也会在所有条件下执行。所以它会关闭所有与数据库相关的对象,避免造成错误。

Closing Database Connections in Java

答案 2 :(得分:0)

您可能遇到过这种情况:

  • 您有触发每个DDL语句的触发器
  • 此触发器尝试将记录插入某种审计/日志表
  • 您的审核/日志表已被清理脚本删除

要获取所有触发器的列表,您可以使用

select * from dba_triggers
where trigger_type not in ('BEFORE EACH ROW','AFTER EACH ROW')

(您可以排除行级触发器,因为它们在概念上属于表,并且在删除表时会自动删除)。在确定违规触发器后,您可以禁用或删除它。