There are at least three problems with your servlet's use of dbConnection.

(1) The connection should not kept in an instance field--use a local
variable.  Servlet instances may typically be shared by many requests, so
you are going to have contention for this object if it is a field.  Besides,
you connect and disconnect in the post method, so why bother maintaining the
reference any longer than that?

(2) The call to cleanUp should probably be in a finally block, not a catch
block.

(3) Before you call close you should verify that dbConnection is non-null.

BTW, your exception log points to the exact line where the problem occurred.
This sort of thing should be easy for you to find next time round.

Stuart Halloway
DevelopMentor
http://staff.develop.com/halloway

> Hi, I have a Sun Microsystems machine, on this machine a .jsp page that
> inovkes a servlet called InsContactenos, when the page call the servlet it
> returns an error.  I dont know wht must be happening, any one of you can
> help me? In previos messages i received your help and it worked
> fine!!! now
> I need some help again.  Thanks in advance,  the log looks like this:
> This is the servlet:
<snip>
>
>
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.sql.*;
>
> public class InsContactenos extends HttpServlet{
>
>
> protected String dbURL = "jdbc:odbc:orclx07";
> protected String dbuserID = "xxx";
> protected String dbpasswd = "xxx";
> protected Connection dbConnection;
> protected PreparedStatement stmt;
>
> public void doPost(HttpServletRequest req, HttpServletResponse res) throws
> ServletException, IOException
>         {
>
>         try{
>         String Fecha_Recibo = req.getParameter("Fecha_Recibo");
>         String Email_Origen = req.getParameter("Email_Origen");
>         String Destinatario = req.getParameter("Destinatario");
>         String Asunto = req.getParameter("Asunto");
>         String Cc = req.getParameter("Cc");
>         String Texto = req.getParameter("Texto");
>
>         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
>         dbConnection =
> DriverManager.getConnection("jdbc:oracle:oci:solutech/solutech@orclx07");
>
>         Statement stmt = dbConnection.createStatement();
>
>         String sql= "INSERT INTO bdct_conepros (FECHRECI, EMAILORIG,
> EMAILDEST, ASUNCONE, COPICONE,  DATAMENS, FECHRESP, DATARESP) VALUES ('" +
> Fecha_Recibo + "', '" + Email_Origen +"', '" +  Destinatario + "', '" +
> Asunto + "', '" + Cc + "','" + Texto + "', ' ', ' ', ' '";
>
>         ResultSet rs = stmt.executeQuery(sql);
>         stmt.close();
>         dbConnection.close();
>         }
>         catch (Exception e)
>         {
>             cleanUp();
>             e.printStackTrace();
>         }
>
>
>         }
>
>
>     public void cleanUp()
>     {
>         try {
>             System.out.println("Closing database connection");
>             dbConnection.close();
>         }
>         catch (SQLException e)
>         {
>             e.printStackTrace();
>         }
>     }
>
>
> }

___________________________________________________________________________
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