0

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. 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();
        }           
    }    
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350

3 Answers3

0

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. I believe this is where you get the java.sql.SQLException: ORA-00604.

Please close them inside a finally{} block and check whether you get the same exception error. Keep that as a good practice.

Hope this would help you to overcome the issue.

Nomesh DeSilva
  • 1,649
  • 4
  • 25
  • 43
0

You have not closed your connection object established for the 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. so it closes all database related objects which avoids errors caused .

Closing Database Connections in Java

Community
  • 1
  • 1
Santhosh
  • 8,181
  • 4
  • 29
  • 56
0

You might have run into this scenario:

  • you have a trigger that fires for every DDL statement
  • 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.

Darshan Lila
  • 5,772
  • 2
  • 24
  • 34