Closing the resultset, statement and connection.
When you leave the method, the connection is only
"marked to kill", and the garbage collection mechanism will handle it
at a later time. When you run out the number of
allowed connection, the database goes bannanas.

DD

----------
From:   Barranger Ridler[SMTP:[EMAIL PROTECTED]]
Sent:   Saturday, April 08, 2000 10:09 PM
To:     [EMAIL PROTECTED]
Subject:        Db connection crashes servlet server

Hello there,

        I have a simple servlet that connects to an access database to check the
name and password of a user.  While it does check this correctly, the server
will crash a few minutes later (Possibly when the distroy() method is
called?? which has no code).  Anyways any help would definately help.
Here's the code that is used to connect.  Sorry about the length

Barranger

        /**
         * Check the User Name and Password
         */
        public boolean login(String name, String pwd)
        {
                //Set the Variables to connect to the Database
                String URL = "jdbc:odbc:Mail";
        String username = "";
        String password = "";

                //Try to load the appropriate Driver
        try
                {
                        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        }
                catch (Exception e)
                {
            return false;
        }

                //Declare the Objects
        Statement  stmt = null;
        Connection con  = null;

                //Create the Objects
        try
                {
            con = DriverManager.getConnection (URL, username, password);
            stmt = con.createStatement();
        }
                catch (Exception e)
                {
                        return false;
        }

                //Declare and Create the ResultSet object
                try
                {
            ResultSet result = stmt.executeQuery
                                (
                                        "SELECT * FROM user WHERE user_name = '" + 
name +
                                        "' AND user_password = '" + pwd + "';"
                                );

                        //If there are any records then the user exists
                        if(result.next())
                        {
                                return true;
                        }
                        else
                        {
                                return false;
                        }
                }
                catch (Exception e)
                {
                        return false;
                }
        }

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to