简体   繁体   English

Java.sql.SQLException:ORA-00604

[英]Java.sql.SQLException: ORA-00604

I developed a website using jsp and servlet but it gives exception java.sql.SQLException: ORA-00604.After restarting the server it is working fine. 我使用jsp和servlet开发了一个网站,但它给出了异常java.sql.SQLException:ORA-00604。重新启动服务器后,它可以正常工作。 Below is my code 下面是我的代码

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();
        }           
    }    
}

I can see you have opened couple of statements and prepared statements : 我可以看到您已经打开了一些语句和准备好的语句

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

but I was unable to see you are closing them properly in a finally{} block. 但是我看不到您在finally {}块中正确关闭了它们。 I believe this is where you get the java.sql.SQLException: ORA-00604. 我相信这是您获得java.sql.SQLException的地方:ORA-00604。

Please close them inside a finally{} block and check whether you get the same exception error. 请在finally{}块中将其关闭,并检查是否遇到相同的异常错误。 Keep that as a good practice. 保持良好习惯。

Hope this would help you to overcome the issue. 希望这可以帮助您解决问题。

You have not closed your connection object established for the sql connection. 您尚未关闭为sql连接建立的connection对象。 It is also advisable to close all your statements , resultsets and connection objects . 建议您关闭所有语句,结果集和连接对象。

finally{
resultset.close();
statement.close();
connection.close();
}

finally block executes on all conditions even on errors. finally块将在所有条件下执行,即使发生错误也是如此。 so it closes all database related objects which avoids errors caused . 因此,它将关闭所有与数据库相关的对象,从而避免引起错误。

Closing Database Connections in Java 用Java关闭数据库连接

You might have run into this scenario: 您可能会遇到这种情况:

  • you have a trigger that fires for every DDL statement 您有一个触发器为每个DDL语句触发
  • this trigger tries to insert records into some kind of audit/log table 此触发器尝试将记录插入某种审计/日志表中
  • you audit/log table was dropped by your cleanup script 您的清理脚本删除了审计/日志表

To get a list of all triggers, you can use 要获取所有触发器的列表,可以使用

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

(you can exclude row-level triggers because they conceptually belong to the table and would have been automatically dropped when you dropped the table). (您可以排除行级触发器,因为它们在概念上属于表,并且在删除表时会被自动删除)。 After you've identified the offending trigger, you can either disable or drop it. 在确定了令人讨厌的触发器之后,可以禁用或删除它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM