Could someone help me out here,
I would like to know if my code is correct. I.e. should I be closing
connections, statements and resultsets before or after connection or
both?

Also in my finally clause, how do I log the error messages?

Any other pointers would gratefully be received.

Thanks in advance -

Sam Rose

import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class newlite extends HttpServlet {

        public void dostuff (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

                //code

                try {   Class.forName( "oracle.jdbc.driver.OracleDriver" );
                        os.println("<p>");
                }
                catch (java.lang.ClassNotFoundException e) {
                        os.print("ClassNotFound: ");
                        os.println(e.getMessage());
                }
                try {

                        con = DriverManager.getConnection( connection code );

                        //code

                        return;
                }//endtry
                catch (java.sql.SQLException ex) {
                        os.println("SQLExcption: " + ex.getMessage());
                }//endcatch

                finally  {
                        try {
                                if (con != null) con.close();
                                if (stmt != null) stmt.close();
                        }
                        catch (java.sql.SQLException ex) {}
                }//endfinally

                os.flush();

        }//end dostuff

        public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
                dostuff(req, res);
        }

        public void doPost (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
                dostuff(req, res);
        }

}//end

___________________________________________________________________________
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