You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Aitor Garcia | Tempel.es" <ag...@tempel.es> on 2011/12/14 17:21:09 UTC

dbcp is mixing up connections

Hi,

After three days of research I've found notthing that helps me to solve 
this problem, it's why I'm trying to get help from the list.

I'm getting connections from dbcp pool in this way:

    /*********************************************************/
    /* Open a connection to the database                     */
    /*********************************************************/


    // AITOR 13/12/2011
    // Seems that connections stay active
    java.sql.Connection conn = null;

    // PreparedStatement prestmt = null;
    Statement stmt = null;
    ResultSet res = null;

    /*********************************************************/
    /* Open a connection to the database                     */
    /*********************************************************/

    public boolean web_dbConnect()  throws SQLException
    {

         try
         {
             javax.naming.Context initContext = new
    javax.naming.InitialContext();
              javax.naming.Context envContext  = (javax.naming.Context)
    initContext.lookup("java:/comp/env");
             javax.sql.DataSource datasource = (javax.sql.DataSource)
    envContext.lookup("jdbc/localpool");

             // get connection from datasource
             conn = datasource.getConnection();

             // wrap the connection with log4jdbc
             conn = new net.sf.log4jdbc.ConnectionSpy(conn);

             // now use Connection as normal (but it will be audited by
    log4jdbc)
             web_dbLog("Get DB Connection '" + conn + "'");

             /*
             DatabaseMetaData meta = conn.getMetaData();

             web_dbLog("Driver Name: " + meta.getDriverName());
             web_dbLog("Driver Version: " + meta.getDriverVersion());
             web_dbLog("Max Connections: " + meta.getMaxConnections());
             */

             /*
             ResultSet res = meta.getTables(null, null, "%", null);

             while (res.next())
             {
                 web_dbLog(res.getString(3));
             }
             */
         }
         catch( javax.naming.NamingException ne )
         {
             // throw new RuntimeException( "Unable to aquire data
    source", ne );
             web_dbLog("ERROR: Unable to aquire DB Connection from
    Datasource");

             return (false);


         }



         return (true);

    }


Closing connection here:


    /*********************************************************/
    /* Close the connection to the database                     */
    /*********************************************************/

    public void web_dbClose() throws SQLException
    {
         // Never close the database connection, because
         // it may interfere with other scripts which
         // share the same connection.
         web_dbLog("Return DB Conection to pool");




         if(res == null)
         {
             web_dbLog("Sorry, ResultSet in null");
         }
         else
         {
             res.close();
             res = null;

             web_dbLog("ResultSet closed!");
         }


         if(stmt == null)
         {
             web_dbLog("Sorry, Statement in null");
         }
         else
         {
             stmt.close();
             stmt = null;

             web_dbLog("Statement closed!");
         }

         if(conn == null)
         {
             web_dbLog("Sorry, Connection in null");
         }
         else
         {
             conn.close();
             conn = null;

             web_dbLog("Connection closed!");
         }
    }


All was working UNTIL AJAX comes. I have an AJAX script that launches 
different JSP scripts at the same time, and seems that comcat mix the 
connections:

The .jsp just

1) Opens connections
2) Make a SELECT statement
3) Make an UPDATE
2) Close a connection

See the code:


     String SQL = "";


    web_dbConnect();

     HashMap section = new HashMap();

     // Que valor tiene actualmente el menú
     SQL = "SELECT ... ";



     section = web_getElem(SQL);





     SQL = "UPDATE "...;



     web_dbUpdate(SQL);



     web_dbClose();



Code works well but connections mix, I have installed log4jdbc to see 
whan happens & the probler arise with the micure of connections into 
different threads:

    15 [http-bio-8080-exec-4] INFO jdbc.connection - 1. Connection
    opened 15 [http-bio-8080-exec-4] INFO jdbc.audit - 1. Connection.new
    Connection returned 16 [http-bio-8080-exec-6] INFO jdbc.connection -
    2. Connection opened 17 [http-bio-8080-exec-7] INFO jdbc.connection
    - 3. Connection opened 17 [http-bio-8080-exec-7] INFO jdbc.audit -
    3. Connection.new Connection returned 17 [http-bio-8080-exec-6] INFO
    jdbc.audit - 2. Connection.new Connection returned 17
    [http-bio-8080-exec-2] INFO jdbc.connection - 4. Connection opened
    17 [http-bio-8080-exec-2] INFO jdbc.audit - 4. Connection.new
    Connection returned 22 [http-bio-8080-exec-7] INFO jdbc.audit - 4.
    Statement.new Statement returned 22 [http-bio-8080-exec-7] INFO
    jdbc.audit - 4. Connection.createStatement(1004, 1007) returned
    net.sf.log4jdbc.StatementSpy@3a0589 22 [http-bio-8080-exec-6] INFO
    jdbc.audit - 4. Statement.new Statement returned 22
    [http-bio-8080-exec-7] INFO jdbc.sqlonly - SELECT ... 22
    [http-bio-8080-exec-4] INFO jdbc.audit - 4. Statement.new Statement
    returned 22 [http-bio-8080-exec-4] INFO jdbc.audit - 4.
    Connection.createStatement(1004, 1007) returned
    net.sf.log4jdbc.StatementSpy@12a2259 23 [http-bio-8080-exec-4] INFO
    jdbc.sqlonly - SELECT... 22 [http-bio-8080-exec-6] INFO jdbc.audit -
    4. Connection.createStatement(1004, 1007) returned
    net.sf.log4jdbc.StatementSpy@14177f3 23 [http-bio-8080-exec-6] INFO
    jdbc.sqlonly - SELECT ... 36 [http-bio-8080-exec-7] INFO
    jdbc.sqltiming - SELECT.... {executed in 13 msec} 42
    [http-bio-8080-exec-7] INFO jdbc.resultset - 4. ResultSet.new
    ResultSet returned 42 [http-bio-8080-exec-7] INFO jdbc.audit - 4.
    Statement.executeQuery(SELECT ... ) returned
    net.sf.log4jdbc.ResultSetSpy@2a2ae9 42 [http-bio-8080-exec-7] INFO
    jdbc.resultset - 4. ResultSet.getRow() returned 0 42
    [http-bio-8080-exec-7] INFO jdbc.resultset - 4. ResultSet.last()
    returned true 42 [http-bio-8080-exec-7] INFO jdbc.resultset - 4.
    ResultSet.getRow() returned 0 42 [http-bio-8080-exec-7] INFO
    jdbc.resultset - 4. ResultSet.beforeFirst() returned 57
    [http-bio-8080-exec-2] INFO jdbc.audit - 4. Statement.new Statement
    returned 57 [http-bio-8080-exec-2] INFO jdbc.audit - 4.
    Connection.createStatement(1004, 1007) returned
    net.sf.log4jdbc.StatementSpy@1b56848 57 [http-bio-8080-exec-2] INFO
    jdbc.sqlonly - SELECT.... 60 [http-bio-8080-exec-4] INFO
    jdbc.sqltiming - SELECT... {executed in 37 msec} 60
    [http-bio-8080-exec-4] INFO jdbc.resultset - 4. ResultSet.new
    ResultSet returned 60 [http-bio-8080-exec-4] INFO jdbc.audit - 4.
    Statement.executeQuery(SELECT ... ) returned
    net.sf.log4jdbc.ResultSetSpy@1c26db4 60 [http-bio-8080-exec-4] INFO
    jdbc.resultset - 4. ResultSet.getRow() returned 0 60
    [http-bio-8080-exec-4] INFO jdbc.resultset - 4. ResultSet.last()
    returned true 60 [http-bio-8080-exec-4] INFO jdbc.resultset - 4.
    ResultSet.getRow() returned 0 60 [http-bio-8080-exec-4] INFO
    jdbc.resultset - 4. ResultSet.beforeFirst() returned 96
    [http-bio-8080-exec-6] INFO jdbc.sqltiming - SELECT ... {executed in
    73 msec} 96 [http-bio-8080-exec-6] INFO jdbc.resultset - 4.
    ResultSet.new ResultSet returned 96 [http-bio-8080-exec-6] INFO
    jdbc.audit - 4. Statement.executeQuery(SELECT ...) returned
    net.sf.log4jdbc.ResultSetSpy@1b0620c 96 [http-bio-8080-exec-6] INFO
    jdbc.resultset - 4. ResultSet.getRow() returned 0 96
    [http-bio-8080-exec-6] INFO jdbc.resultset - 4. ResultSet.last()
    returned true 96 [http-bio-8080-exec-6] INFO jdbc.resultset - 4.
    ResultSet.getRow() returned 0 96 [http-bio-8080-exec-6] INFO
    jdbc.resultset - 4. ResultSet.beforeFirst() returned 102
    [http-bio-8080-exec-4] INFO jdbc.audit - 4. PreparedStatement.new
    PreparedStatement returned 102 [http-bio-8080-exec-7] INFO
    jdbc.audit - 4. PreparedStatement.new PreparedStatement returned 102
    [http-bio-8080-exec-4] INFO jdbc.audit - 4.
    Connection.prepareStatement(UPDATE ...) returned
    net.sf.log4jdbc.PreparedStatementSpy@d4a1d3 102
    [http-bio-8080-exec-7] INFO jdbc.audit - 4.
    Connection.prepareStatement(UPDATE ...) returned
    net.sf.log4jdbc.PreparedStatementSpy@1cc3baa 103
    [http-bio-8080-exec-4] INFO jdbc.sqlonly - UPDATE ... 103
    [http-bio-8080-exec-7] INFO jdbc.sqlonly - UPDATE .... 133
    [http-bio-8080-exec-2] INFO jdbc.sqltiming - SELECT ... {executed in
    76 msec} 133 [http-bio-8080-exec-2] INFO jdbc.resultset - 4.
    ResultSet.new ResultSet returned 133 [http-bio-8080-exec-2] INFO
    jdbc.audit - 4. Statement.executeQuery(SELECT ... ) returned
    net.sf.log4jdbc.ResultSetSpy@1611aec 133 [http-bio-8080-exec-2] INFO
    jdbc.resultset - 4. ResultSet.getRow() returned 0 133
    [http-bio-8080-exec-2] INFO jdbc.resultset - 4. ResultSet.last()
    returned true 133 [http-bio-8080-exec-2] INFO jdbc.resultset - 4.
    ResultSet.getRow() returned 0 133 [http-bio-8080-exec-2] INFO
    jdbc.resultset - 4. ResultSet.beforeFirst() returned 134
    [http-bio-8080-exec-6] INFO jdbc.audit - 4. PreparedStatement.new
    PreparedStatement returned 134 [http-bio-8080-exec-6] INFO
    jdbc.audit - 4. Connection.prepareStatement(UPDATE ...) returned
    net.sf.log4jdbc.PreparedStatementSpy@2e9c76 135
    [http-bio-8080-exec-6] INFO jdbc.sqlonly - UPDATE ... 197
    [http-bio-8080-exec-7] INFO jdbc.sqltiming - UPDATE ... {executed in
    93 msec} 197 [http-bio-8080-exec-7] INFO jdbc.audit - 4.
    PreparedStatement.executeUpdate() returned 1 225
    [http-bio-8080-exec-8] INFO jdbc.connection - 5. Connection opened
    225 [http-bio-8080-exec-8] INFO jdbc.audit - 5. Connection.new
    Connection returned 227 [http-bio-8080-exec-8] INFO jdbc.audit - 5.
    Statement.new Statement returned 227 [http-bio-8080-exec-8] INFO
    jdbc.audit - 5. Connection.createStatement(1004, 1007) returned
    net.sf.log4jdbc.StatementSpy@11f2041 227 [http-bio-8080-exec-8] INFO
    jdbc.sqlonly - SELECT ... 249 [http-bio-8080-exec-4] INFO
    jdbc.sqltiming - UPDATE .... {executed in 146 msec} 249
    [http-bio-8080-exec-4] INFO jdbc.audit - 4.
    PreparedStatement.executeUpdate() returned 1 250
    [http-bio-8080-exec-8] INFO jdbc.sqltiming - SELECT ... {executed in
    23 msec} 250 [http-bio-8080-exec-8] INFO jdbc.resultset - 5.
    ResultSet.new ResultSet returned 250 [http-bio-8080-exec-8] INFO
    jdbc.audit - 5. Statement.executeQuery(SELECT ... ) returned
    net.sf.log4jdbc.ResultSetSpy@7e942f 250 [http-bio-8080-exec-8] INFO
    jdbc.resultset - 5. ResultSet.getRow() returned 0 250
    [http-bio-8080-exec-8] INFO jdbc.resultset - 5. ResultSet.last()
    returned true 250 [http-bio-8080-exec-8] INFO jdbc.resultset - 5.
    ResultSet.getRow() returned 0 250 [http-bio-8080-exec-8] INFO
    jdbc.resultset - 5. ResultSet.beforeFirst() returned 250
    [http-bio-8080-exec-7] INFO jdbc.audit - 4.
    PreparedStatement.close() returned 251 [http-bio-8080-exec-10] INFO
    jdbc.connection - 6. Connection opened 251 [http-bio-8080-exec-10]
    INFO jdbc.audit - 6. Connection.new Connection returned 252
    [http-bio-8080-exec-10] INFO jdbc.audit - 6. Statement.new Statement
    returned 252 [http-bio-8080-exec-10] INFO jdbc.audit - 6.
    Connection.createStatement(1004, 1007) returned
    net.sf.log4jdbc.StatementSpy@74ece8 252 [http-bio-8080-exec-10] INFO
    jdbc.sqlonly - SELECT... 261 [http-bio-8080-exec-10] INFO
    jdbc.sqltiming - SELECT ... {executed in 9 msec} 261
    [http-bio-8080-exec-10] INFO jdbc.resultset - 6. ResultSet.new
    ResultSet returned 261 [http-bio-8080-exec-10] INFO jdbc.audit - 6.
    Statement.executeQuery(SELECT ...) returned
    net.sf.log4jdbc.ResultSetSpy@165d118 261 [http-bio-8080-exec-10]
    INFO jdbc.resultset - 6. ResultSet.getRow() returned 0 261
    [http-bio-8080-exec-10] INFO jdbc.resultset - 6. ResultSet.last()
    returned true 261 [http-bio-8080-exec-10] INFO jdbc.resultset - 6.
    ResultSet.getRow() returned 0 261 [http-bio-8080-exec-10] INFO
    jdbc.resultset - 6. ResultSet.beforeFirst() returned 264
    [http-bio-8080-exec-10] INFO jdbc.audit - 6. PreparedStatement.new
    PreparedStatement returned 264 [http-bio-8080-exec-10] INFO
    jdbc.audit - 6. Connection.prepareStatement(UPDATE ...) returned
    net.sf.log4jdbc.PreparedStatementSpy@18297fe 264
    [http-bio-8080-exec-8] INFO jdbc.audit - 5. PreparedStatement.new
    PreparedStatement returned 264 [http-bio-8080-exec-8] INFO
    jdbc.audit - 5. Connection.prepareStatement(UPDATE....) returned
    net.sf.log4jdbc.PreparedStatementSpy@c8aeb3 269
    [http-bio-8080-exec-7] INFO jdbc.resultset - 5. ResultSet.close()
    returned 269 [http-bio-8080-exec-10] INFO jdbc.sqlonly - UPDATE ....
    278 [http-bio-8080-exec-8] INFO jdbc.sqlonly - UPDATE... 340
    [http-bio-8080-exec-6] INFO jdbc.sqltiming - UPDATE .. {executed in
    205 msec} 340 [http-bio-8080-exec-6] INFO jdbc.audit - 4.
    PreparedStatement.executeUpdate() returned 1 341
    [http-bio-8080-exec-2] INFO jdbc.audit - 4. PreparedStatement.new
    PreparedStatement returned 341 [http-bio-8080-exec-2] INFO
    jdbc.audit - 4. Connection.prepareStatement(UPDATE ...) returned
    net.sf.log4jdbc.PreparedStatementSpy@5f634c 342
    [http-bio-8080-exec-6] INFO jdbc.audit - 4.
    PreparedStatement.close() returned 343 [http-bio-8080-exec-4] INFO
    jdbc.audit - 4. PreparedStatement.close() returned 344
    [http-bio-8080-exec-2] INFO jdbc.sqlonly - UPDATE ... 365
    [http-bio-8080-exec-2] INFO jdbc.sqltiming - UPDATE ... {executed in
    21 msec} 365 [http-bio-8080-exec-2] INFO jdbc.audit - 4.
    PreparedStatement.executeUpdate() returned 1 367
    [http-bio-8080-exec-2] INFO jdbc.audit - 4.
    PreparedStatement.close() returned 428 [http-bio-8080-exec-10] INFO
    jdbc.sqltiming - UPDATE ...' {executed in 159 msec} 428
    [http-bio-8080-exec-10] INFO jdbc.audit - 6.
    PreparedStatement.executeUpdate() returned 1 431
    [http-bio-8080-exec-7] INFO jdbc.audit - 6. Statement.close()
    returned 433 [http-bio-8080-exec-7] INFO jdbc.connection - 6.
    Connection closed 433 [http-bio-8080-exec-7] INFO jdbc.audit - 6.
    Connection.close() returned 436 [http-bio-8080-exec-10] INFO
    jdbc.audit - 6. PreparedStatement.close() returned 436
    [http-bio-8080-exec-8] INFO jdbc.sqltiming - UPDATE ... {executed in
    158 msec} 436 [http-bio-8080-exec-8] INFO jdbc.audit - 5.
    PreparedStatement.executeUpdate() returned 1 439
    [http-bio-8080-exec-6] INFO jdbc.audit - 6. Statement.close()
    returned 439 [http-bio-8080-exec-4] INFO jdbc.audit - 6.
    Statement.close() returned 439 [http-bio-8080-exec-2] INFO
    jdbc.audit - 6. Statement.close() returned 453
    [http-bio-8080-exec-8] INFO jdbc.audit - 5.
    PreparedStatement.close() returned 



I've tested this into : Centos / Windows Vista
Tomcat : 7.0 (diferent )
Java: Jre 1.6.0_16, 1.7.0 & 1.7.2

And happens the same.

Thnks. Any help would be appreciated!


-- 

FIRMA


Estemensaje se dirige exclusivamente a su destinatario. Contiene 
información *CONFIDENCIAL* sometida a secreto profesional o cuya 
divulgación está prohibida por Ley.
Si ha recibido este mensaje por error, debe saber que su lectura, copia 
y uso están prohibidos.
Le rogamos nos lo comunique inmediatamente por esta misma vía o por 
teléfono 93 600 36 00y proceda a su destrucción.
El correo electrónico vía Internet no permite asegurar la 
confidencialidad de los mensajes que se transmiten ni su integridad o 
correcta recepción.
*TEMPEL S.A.*no asume responsabilidad por estas circunstancias. Si el 
destinatario de este mensaje no consintiera la utilización del correo 
electrónico vía Internet y la grabación de los mensajes, rogamos lo 
ponga en nuestro conocimiento de forma inmediata.
En cumplimiento de la Ley Orgánica 15/1999, de 13 de diciembre, de 
Protección de Datos de Carácter Personal le informamos de que sus datos 
personales y de empresa pasarán a formar parte de un fichero registrado 
ante la Agencia Española de Protección de Datos.
Los datos personales que existen en nuestro poder están protegidos por 
nuestra Política de Seguridad, y no serán compartidos con ninguna otra 
empresa.
Usted puede ejercitar sus derechos de acceso, rectificación, cancelación 
y oposición dirigiéndose por escrito a c/ Cobalto, 4 08907 L'Hospitalet 
de LLobregat (Barcelona).


Re: dbcp is mixing up connections

Posted by Pid <pi...@pidster.com>.
On 15/12/2011 12:55, Aitor Garcia | Tempel.es wrote:
> I had read all the JNDI & JDBC Official & Unofficial documentation but &
> only found than you MUST close the connections.
> 
> There insn't references to where to declare variables.
> 
> Declaring into local scope forces that you have pass by reference the
> connection, statement and resultset in every function that handle the
> pool os use a class to handle the connection itsef.

Strongly recommend not doing any of this in a JSP.  Look up MVC.


p



> FIRMA
> 
> 
> Este  mensaje se dirige exclusivamente a su destinatario. Contiene
> información *CONFIDENCIAL* sometida a secreto profesional o cuya
> divulgación está prohibida por Ley.
> Si ha recibido este mensaje por error, debe saber que su lectura, copia
> y uso están prohibidos.
> Le rogamos nos lo comunique inmediatamente por esta misma vía o por
> teléfono 93 600 36 00  y proceda a su destrucción.
> El correo electrónico vía Internet no permite asegurar la
> confidencialidad de los mensajes que se transmiten ni su integridad o
> correcta recepción.
> *TEMPEL S.A.*no asume responsabilidad por estas circunstancias. Si el
> destinatario de este mensaje no consintiera la utilización del correo
> electrónico vía Internet y la grabación de los mensajes, rogamos lo
> ponga en nuestro conocimiento de forma inmediata.
> En cumplimiento de la Ley Orgánica 15/1999, de 13 de diciembre, de
> Protección de Datos de Carácter Personal le informamos de que sus datos
> personales y de empresa pasarán a formar parte de un fichero registrado
> ante la Agencia Española de Protección de Datos.
> Los datos personales que existen en nuestro poder están protegidos por
> nuestra Política de Seguridad, y no serán compartidos con ninguna otra
> empresa.
> Usted puede ejercitar sus derechos de acceso, rectificación, cancelación
> y oposición dirigiéndose por escrito a c/ Cobalto, 4 08907 L'Hospitalet
> de LLobregat (Barcelona).
> 
> 
> El 15/12/2011 13:40, Mark Thomas escribió:
>> On 15/12/2011 12:12, Aitor Garcia | Tempel.es wrote:
>>> I don't know if this is a tomcat bug.
>> This is clearly not a Tomcat bug. This comes under the category of "user
>> error".
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>


-- 

[key:62590808]


Re: dbcp is mixing up connections

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/12/15 Aitor Garcia | Tempel.es <ag...@tempel.es>
>
> I had read all the JNDI & JDBC Official & Unofficial documentation but & only found than you MUST close the connections.


That is why you have to read  the Servlet specification, JSP specification, etc.


> There insn't references to where to declare variables.
>
> Declaring into local scope forces that you have pass by reference the connection, statement and resultset in every function that handle the pool os use a class to handle the connection itsef.
>

Eh? There are many ways to write a program. Have you ever heard about
encapsulation? About patterns (such as "Design Patterns" book by
E.Gamma &co)?
http://www.ibookdb.net/isbn/0201633612


One more important thing to learn:
You should NEVER send HTML e-mails and images to mailing lists. It
wastes subscribers' bandwidth and storage area on archive servers.
Please use plain text.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: dbcp is mixing up connections

Posted by "Aitor Garcia | Tempel.es" <ag...@tempel.es>.
I had read all the JNDI & JDBC Official & Unofficial documentation but & 
only found than you MUST close the connections.

There insn't references to where to declare variables.

Declaring into local scope forces that you have pass by reference the 
connection, statement and resultset in every function that handle the 
pool os use a class to handle the connection itsef.

FIRMA


Estemensaje se dirige exclusivamente a su destinatario. Contiene 
información *CONFIDENCIAL* sometida a secreto profesional o cuya 
divulgación está prohibida por Ley.
Si ha recibido este mensaje por error, debe saber que su lectura, copia 
y uso están prohibidos.
Le rogamos nos lo comunique inmediatamente por esta misma vía o por 
teléfono 93 600 36 00y proceda a su destrucción.
El correo electrónico vía Internet no permite asegurar la 
confidencialidad de los mensajes que se transmiten ni su integridad o 
correcta recepción.
*TEMPEL S.A.*no asume responsabilidad por estas circunstancias. Si el 
destinatario de este mensaje no consintiera la utilización del correo 
electrónico vía Internet y la grabación de los mensajes, rogamos lo 
ponga en nuestro conocimiento de forma inmediata.
En cumplimiento de la Ley Orgánica 15/1999, de 13 de diciembre, de 
Protección de Datos de Carácter Personal le informamos de que sus datos 
personales y de empresa pasarán a formar parte de un fichero registrado 
ante la Agencia Española de Protección de Datos.
Los datos personales que existen en nuestro poder están protegidos por 
nuestra Política de Seguridad, y no serán compartidos con ninguna otra 
empresa.
Usted puede ejercitar sus derechos de acceso, rectificación, cancelación 
y oposición dirigiéndose por escrito a c/ Cobalto, 4 08907 L'Hospitalet 
de LLobregat (Barcelona).


El 15/12/2011 13:40, Mark Thomas escribió:
> On 15/12/2011 12:12, Aitor Garcia | Tempel.es wrote:
>> I don't know if this is a tomcat bug.
> This is clearly not a Tomcat bug. This comes under the category of "user
> error".
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

Re: dbcp is mixing up connections

Posted by Mark Thomas <ma...@apache.org>.
On 15/12/2011 12:12, Aitor Garcia | Tempel.es wrote:
> I don't know if this is a tomcat bug.

This is clearly not a Tomcat bug. This comes under the category of "user
error".

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] dbcp is mixing up connections

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Aitor,

(Marking OT because this has nothing to do with Tomcat or even with
the original thread. I may be feeding a troll, here. Apologies in
advance.)

On 12/16/11 4:31 AM, Aitor Garcia | Tempel.es wrote:
> I'm not an expert but in past I worked a with MVC, Swing and JAVA:
> Cool stuff, but I never have seen how it helps in the web
> development.

MVS is an architectural design suggestion, and it applies pretty much
everywhere. I can show you how how MVC pattern can be applied to a
variety of tasks from writing a compiler to writing scripting engine
and GUI to control turbine-engine test beds.

Swing doesn't help you in web development, but if you've written your
Swing-based apps properly, then replacing the Swing front-end with a
web-based one should require only the replacement of the interface
code: no migration of JDBC calls, etc.

> Java turned into the web, makes huge amount of writing (the exact 
> formula is : lines_of_JSP_code = lines_of_PHP_code * 10) & no way
> to fit objects/classes, into Web Application needs.

That's funny... when I write PHP, I long for Java. I'm kind of a
stickler for proper resource management, and having to check every
single db_query(...) call for an error code, then clean-up all the
statements I've executed and results I've fetched, then close the
connection and repeat the same code over and over and over again seems
like a waste of typing.

As for "[fitting] objects/classes into Web Application needs", I
suspect that you haven't really made the leap from procedural
programming into object-oriented programming. I'm not suggesting that
one is better than the other -- just that there really is a completely
different mindset when writing with objects in mind. I used to get
irritated when everyone used the term "paradigm shift" to describe it,
so I won't use that term, here. Damn.

> Have you seen Hashes in PHP?

Yes, the syntax is charming.

> try to use them in java... Ehhh and don't put an Integer into a 
> HashMap and try to get a String!!

This is the difference between strongly-typed and loosely-typed
languages. It's another one of those things you just have to get used
to. The upside is that the runtime doesn't have to waste all it's time
trying to figure out what type everything is and convert everything on
the fly.

> You have to then Integer Values with a Try() Catch()

You're doing it wrong if you have to use try/catch to fetch values
from a hash table.

> Swith statement does not support Strings!!!...

That's right: switch only supports primitive data types. You'll have
to do things the "long" way and use a series of "if". Oh, noes.

> thinks like this fucks a lot!

I've entertained your rant long enough. Please don't use language like
this on the list. It's really not necessary. When I can't get
something working in PHP, I read the documentation and figure it out.
I don't go into a PHP-related mailing list and make a complete ass out
of myself by complaining about language features and how I hate using it.

> I'm going to read a lot of books but not about JavaServer(TM)
> (Oracle).

I hope you enjoy your Bliss.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7rz8YACgkQ9CaO5/Lv0PADpACgrSRrPQ9hU5hDvLgqJTDUtnP8
4RYAnimfublvv4klQ7e4VaaB4RimR/lZ
=B+Ec
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: dbcp is mixing up connections

Posted by "Aitor Garcia | Tempel.es" <ag...@tempel.es>.
Mark:

I'm just declaring variables there, no putting logic.

You had overlooked log4jdbc, if you have read books in the same way....

Library log4jdbc is COOL! Works very Well, is really a good library that 
helps me a lot, without it I cannot see what really is happening behind 
the scenes. Bravo log4jdbc : http://code.google.com/p/log4jdbc/!!

Terence:

I had read the same, the first time I started a JSP page and rereaded it 
yesterday: http://java.sun.com/products/jsp/pdf/jsptut.pdf.



Maybe I had been never understood how JSP/Beans works or maybe this kind 
programing language simply does not fit.

I'm not an expert but in past I worked a with MVC, Swing and JAVA: Cool 
stuff, but I never have seen how it helps in the web development. Java 
turned into the web, makes huge amount of writing (the exact formula is 
: lines_of_JSP_code = lines_of_PHP_code * 10) & no way to fit 
objects/classes, into Web Application needs. Have you seen Hashes in 
PHP? try to use them in java... Ehhh and don't put an Integer into a 
HashMap and try to get a String!! You have to then Integer Values with a 
Try() Catch(), Swith statement does not support Strings!!!... thinks 
like this fucks a lot!

PHP is a hundred times more versatile for Web, and there is lots and 
lots of support: lib GD is great, making PDFs is preatty simple almost 
every problem you are going to face is resolved and published somewhere, 
you only have to Google a little. I think PHP makes sense, of course in 
conjunction with a good framework.

I'm going to read a lot of books but not about JavaServer(TM) (Oracle).



FIRMA


Estemensaje se dirige exclusivamente a su destinatario. Contiene 
información *CONFIDENCIAL* sometida a secreto profesional o cuya 
divulgación está prohibida por Ley.
Si ha recibido este mensaje por error, debe saber que su lectura, copia 
y uso están prohibidos.
Le rogamos nos lo comunique inmediatamente por esta misma vía o por 
teléfono 93 600 36 00y proceda a su destrucción.
El correo electrónico vía Internet no permite asegurar la 
confidencialidad de los mensajes que se transmiten ni su integridad o 
correcta recepción.
*TEMPEL S.A.*no asume responsabilidad por estas circunstancias. Si el 
destinatario de este mensaje no consintiera la utilización del correo 
electrónico vía Internet y la grabación de los mensajes, rogamos lo 
ponga en nuestro conocimiento de forma inmediata.
En cumplimiento de la Ley Orgánica 15/1999, de 13 de diciembre, de 
Protección de Datos de Carácter Personal le informamos de que sus datos 
personales y de empresa pasarán a formar parte de un fichero registrado 
ante la Agencia Española de Protección de Datos.
Los datos personales que existen en nuestro poder están protegidos por 
nuestra Política de Seguridad, y no serán compartidos con ninguna otra 
empresa.
Usted puede ejercitar sus derechos de acceso, rectificación, cancelación 
y oposición dirigiéndose por escrito a c/ Cobalto, 4 08907 L'Hospitalet 
de LLobregat (Barcelona).


El 16/12/2011 3:32, Mark Eggers escribió:
> ral people

Re: dbcp is mixing up connections

Posted by "Terence M. Bandoian" <te...@tmbsw.com>.
On 1:59 PM, Pid * wrote:
> On 16 Dec 2011, at 09:32, "Aitor Garcia | Tempel.es" <ag...@tempel.es>
> wrote:
>
>  Mark:
>
> I'm just declaring variables there, no putting logic.
>
> You had overlooked log4jdbc, if you have read books in the same way....
>
> Library log4jdbc is COOL! Works very Well, is really a good library that
> helps me a lot, without it I cannot see what really is happening behind the
> scenes. Bravo log4jdbc : http://code.google.com/p/log4jdbc/!!
>
> Terence:
>
> I had read the same, the first time I started a JSP page and rereaded it
> yesterday: http://java.sun.com/products/jsp/pdf/jsptut.pdf.
>
>
>
> Maybe I had been never understood how JSP/Beans works or maybe this kind
> programing language simply does not fit.
>
> I'm not an expert but in past I worked a with MVC, Swing and JAVA: Cool
> stuff, but I never have seen how it helps in the web development. Java
> turned into the web, makes huge amount of writing (the exact formula is :
> lines_of_JSP_code = lines_of_PHP_code * 10) & no way to fit
> objects/classes, into Web Application needs. Have you seen Hashes in PHP?
> try to use them in java... Ehhh and don't put an Integer into a HashMap and
> try to get a String!! You have to then Integer Values with a Try() Catch(),
> Swith statement does not support Strings!!!... thinks like this fucks a lot!
>
> PHP is a hundred times more versatile for Web, and there is lots and lots
> of support: lib GD is great, making PDFs is preatty simple almost every
> problem you are going to face is resolved and published somewhere, you only
> have to Google a little. I think PHP makes sense, of course in conjunction
> with a good framework.
>
> I'm going to read a lot of books but not about JavaServer(TM) (Oracle).
>
>
>
> I think you're on the wrong mailing list.
>
>
> p

But thanks for stopping by.

-Terence

>
> <AITOR_GARCIA.jpg>
>
>
> Este  mensaje se dirige exclusivamente a su destinatario. Contiene
> información *CONFIDENCIAL* sometida a secreto profesional o cuya
> divulgación está prohibida por Ley.
> Si ha recibido este mensaje por error, debe saber que su lectura, copia y
> uso están prohibidos.
> Le rogamos nos lo comunique inmediatamente por esta misma vía o por
> teléfono 93 600 36 00  y proceda a su destrucción.
> El correo electrónico vía Internet no permite asegurar la confidencialidad
> de los mensajes que se transmiten ni su integridad o correcta recepción.
> *TEMPEL S.A.* no asume responsabilidad por estas circunstancias. Si el
> destinatario de este mensaje no consintiera la utilización del correo
> electrónico vía Internet y la grabación de los mensajes, rogamos lo ponga
> en nuestro conocimiento de forma inmediata.
> En cumplimiento de la Ley Orgánica 15/1999, de 13 de diciembre, de
> Protección de Datos de Carácter Personal le informamos de que sus datos
> personales y de empresa pasarán a formar parte de un fichero registrado
> ante la Agencia Española de Protección de Datos.
> Los datos personales que existen en nuestro poder están protegidos por
> nuestra Política de Seguridad, y no serán compartidos con ninguna otra
> empresa.
> Usted puede ejercitar sus derechos de acceso, rectificación, cancelación y
> oposición dirigiéndose por escrito a c/ Cobalto, 4 08907 L'Hospitalet de
> LLobregat (Barcelona).
>
> El 16/12/2011 3:32, Mark Eggers escribió:
>
> ral people
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: dbcp is mixing up connections

Posted by Pid * <pi...@pidster.com>.
On 16 Dec 2011, at 09:32, "Aitor Garcia | Tempel.es" <ag...@tempel.es>
wrote:

 Mark:

I'm just declaring variables there, no putting logic.

You had overlooked log4jdbc, if you have read books in the same way....

Library log4jdbc is COOL! Works very Well, is really a good library that
helps me a lot, without it I cannot see what really is happening behind the
scenes. Bravo log4jdbc : http://code.google.com/p/log4jdbc/!!

Terence:

I had read the same, the first time I started a JSP page and rereaded it
yesterday: http://java.sun.com/products/jsp/pdf/jsptut.pdf.



Maybe I had been never understood how JSP/Beans works or maybe this kind
programing language simply does not fit.

I'm not an expert but in past I worked a with MVC, Swing and JAVA: Cool
stuff, but I never have seen how it helps in the web development. Java
turned into the web, makes huge amount of writing (the exact formula is :
lines_of_JSP_code = lines_of_PHP_code * 10) & no way to fit
objects/classes, into Web Application needs. Have you seen Hashes in PHP?
try to use them in java... Ehhh and don't put an Integer into a HashMap and
try to get a String!! You have to then Integer Values with a Try() Catch(),
Swith statement does not support Strings!!!... thinks like this fucks a lot!

PHP is a hundred times more versatile for Web, and there is lots and lots
of support: lib GD is great, making PDFs is preatty simple almost every
problem you are going to face is resolved and published somewhere, you only
have to Google a little. I think PHP makes sense, of course in conjunction
with a good framework.

I'm going to read a lot of books but not about JavaServer(TM) (Oracle).



I think you're on the wrong mailing list.


p

<AITOR_GARCIA.jpg>


Este  mensaje se dirige exclusivamente a su destinatario. Contiene
información *CONFIDENCIAL* sometida a secreto profesional o cuya
divulgación está prohibida por Ley.
Si ha recibido este mensaje por error, debe saber que su lectura, copia y
uso están prohibidos.
Le rogamos nos lo comunique inmediatamente por esta misma vía o por
teléfono 93 600 36 00  y proceda a su destrucción.
El correo electrónico vía Internet no permite asegurar la confidencialidad
de los mensajes que se transmiten ni su integridad o correcta recepción.
*TEMPEL S.A.* no asume responsabilidad por estas circunstancias. Si el
destinatario de este mensaje no consintiera la utilización del correo
electrónico vía Internet y la grabación de los mensajes, rogamos lo ponga
en nuestro conocimiento de forma inmediata.
En cumplimiento de la Ley Orgánica 15/1999, de 13 de diciembre, de
Protección de Datos de Carácter Personal le informamos de que sus datos
personales y de empresa pasarán a formar parte de un fichero registrado
ante la Agencia Española de Protección de Datos.
Los datos personales que existen en nuestro poder están protegidos por
nuestra Política de Seguridad, y no serán compartidos con ninguna otra
empresa.
Usted puede ejercitar sus derechos de acceso, rectificación, cancelación y
oposición dirigiéndose por escrito a c/ Cobalto, 4 08907 L'Hospitalet de
LLobregat (Barcelona).

El 16/12/2011 3:32, Mark Eggers escribió:

ral people

Re: dbcp is mixing up connections

Posted by Mark Eggers <it...@yahoo.com>.
----- Original Message -----

> From: Terence M. Bandoian <te...@tmbsw.com>
> To: Tomcat Users List <us...@tomcat.apache.org>
> Cc: 
> Sent: Thursday, December 15, 2011 11:31 AM
> Subject: Re: dbcp is mixing up connections
> 
> On 1:59 PM, Christopher Schultz wrote:
>>  Aitor,
>> 
>>  On 12/15/11 7:12 AM, Aitor Garcia | Tempel.es wrote:
>>  > 5) Tomcat, creates ONE (or maybe SOME) Class object and call to the
>>  >  _jspService on every script request
>> 
>>  > What happens if you handle Pool Coonections with a
>>  > 'java.sql.Connection conn' variable declared into the 
> definitions
>>  > block "<%! %>"?
>> 
>>  > Happens than if you are donig multitheading and executing the same
>>  > sctipt in parallel you will mix up connections because evey thead
>>  > is executing the same method in parallel and putting a different
>>  > connection into the java.sql.Connection conn class variable.
>> 
>>  > I don't know if this is a tomcat bug.
>> 
>>  Obviously it's not.
>> 
>>  This is one of the many reasons why application logic has no business
>>  being in a JSP. Whoever proposed (and, indeed approved) the
>>  introduction of scriptlets (<% ... %>) should have been flogged.
>> 
>>  -chris
> 
> Hi, Chris-
> 
> From the Java Server Pages Specification:
> 
> "There are three language-based types of scripting elements:
> declarations, scriptlets, and expressions. Declarations follow the
> syntax <%! ... %>. Scriptlets follow the syntax <% ... %>. 
> Expressions
> follow the syntax <%= ... %>."
> 
> -Terence Bandoian
>

Lots of things are causing problems here.

As many others have pointed out, instance variables are not thread safe. In short, do not put your business logic, database logic, or control logic in a JSP page. You will have problems.

I suggest reading at least two books (plus the servlet spec as others have recommended).

Head First Servlets and JSP by Bryan Basham, Kathy Sierra, and Bert Bates

I've read the first edition. The second edition is out and highly reviewed. It covers a lot of material in a very approachable way. It does have a chapter at the end on MVC, but it is not a design book.

Several people have mentioned the Design Patterns book by the Gang of Four (Gamma et. al). It's a great book, but you may or may not find it approachable.

Head First Design Patterns by Freeman and Freeman is another approachable book, with examples and exercises in Java. It obviously covers design patterns. Even Erich Gamma was impressed (according to the "praise page").

Finally, I took a look at the library you're using to do logging. It appears that what you are trying to do is not supported. See the following two links:

http://code.google.com/p/log4jdbc/wiki/FAQ

http://code.google.com/p/log4jdbc/wiki/DataSourceExampleForWebSphere


In short, it appears that without writing your own factory, you will not get the results you want with this library. Granted, I've not really explored the code that much so I could be completely wrong here.

I do not have any affiliation with any of the books or authors mentioned. I just have found them good learning resources.

just my two cents . . . .
/mde/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: dbcp is mixing up connections

Posted by "Terence M. Bandoian" <te...@tmbsw.com>.
On 1:59 PM, Christopher Schultz wrote:
> Aitor,
>
> On 12/15/11 7:12 AM, Aitor Garcia | Tempel.es wrote:
> > 5) Tomcat, creates ONE (or maybe SOME) Class object and call to the
> >  _jspService on every script request
>
> > What happens if you handle Pool Coonections with a
> > 'java.sql.Connection conn' variable declared into the definitions
> > block "<%! %>"?
>
> > Happens than if you are donig multitheading and executing the same
> > sctipt in parallel you will mix up connections because evey thead
> > is executing the same method in parallel and putting a different
> > connection into the java.sql.Connection conn class variable.
>
> > I don't know if this is a tomcat bug.
>
> Obviously it's not.
>
> This is one of the many reasons why application logic has no business
> being in a JSP. Whoever proposed (and, indeed approved) the
> introduction of scriptlets (<% ... %>) should have been flogged.
>
> -chris

Hi, Chris-

>From the Java Server Pages Specification:

"There are three language-based types of scripting elements:
declarations, scriptlets, and expressions. Declarations follow the
syntax <%! ... %>. Scriptlets follow the syntax <% ... %>. Expressions
follow the syntax <%= ... %>."

-Terence Bandoian


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: dbcp is mixing up connections

Posted by "Terence M. Bandoian" <te...@tmbsw.com>.
On 1:59 PM, Christopher Schultz wrote:
> Aitor,
>
> On 12/15/11 7:12 AM, Aitor Garcia | Tempel.es wrote:
> > 5) Tomcat, creates ONE (or maybe SOME) Class object and call to the
> >  _jspService on every script request
>
> > What happens if you handle Pool Coonections with a
> > 'java.sql.Connection conn' variable declared into the definitions
> > block "<%! %>"?
>
> > Happens than if you are donig multitheading and executing the same
> > sctipt in parallel you will mix up connections because evey thead
> > is executing the same method in parallel and putting a different
> > connection into the java.sql.Connection conn class variable.
>
> > I don't know if this is a tomcat bug.
>
> Obviously it's not.
>
> This is one of the many reasons why application logic has no business
> being in a JSP. Whoever proposed (and, indeed approved) the
> introduction of scriptlets (<% ... %>) should have been flogged.
>
> -chris

Hi, Aitor-

Tomcat reuses JSP class instances in multiple threads.  Variables
defined in declarations blocks <%! ... %> result in member (or instance)
variables.  If you define instance variables, you have to ensure their
usage is thread-safe.

Variables defined in scriptlet blocks <% ... %> result in variables that
are local to the JSP service method.

-Terence Bandoian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: dbcp is mixing up connections

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Aitor,

On 12/15/11 7:12 AM, Aitor Garcia | Tempel.es wrote:
> 5) Tomcat, creates ONE (or maybe SOME) Class object and call to the
>  _jspService on every script request
> 
> What happens if you handle Pool Coonections with a
> 'java.sql.Connection conn' variable declared into the definitions
> block "<%! %>"?
> 
> Happens than if you are donig multitheading and executing the same 
> sctipt in parallel you will mix up connections because evey thead
> is executing the same method in parallel and putting a different
> connection into the java.sql.Connection conn class variable.
> 
> I don't know if this is a tomcat bug.

Obviously it's not.

This is one of the many reasons why application logic has no business
being in a JSP. Whoever proposed (and, indeed approved) the
introduction of scriptlets (<% ... %>) should have been flogged.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7qFLAACgkQ9CaO5/Lv0PBjBgCfeCtAcWmeoSWJsva+VGEevvnU
xvoAoKCMa1i5YwxqbrHkiAeo9SKGe+Rr
=0kQv
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: dbcp is mixing up connections

Posted by "Aitor Garcia | Tempel.es" <ag...@tempel.es>.
Thanks for your answers.

I've found the solution Myself.

1) You have 2 different blocks in a jsp file:

     The one into <%! %> tags is about definition
     The one into <% %> tags is about coding

2) A jsp file (script.jsp) is transfomed by tomcat into a single class 
file into the work directory including the source code of the sceipt 
(with all the includes)

3) 'definition block' goes into the definition part of the class in the 
generated class and 'code block' goes into one method of the class:

      public void _jspService(final 
javax.servlet.http.HttpServletRequest request, final 
javax.servlet.http.HttpServletResponse response)

4) I assume that the Tomcat Container, instances the class depending of 
the retrieved requests. This is WHY Tomcat is a Container.

5) Tomcat, creates ONE (or maybe SOME) Class object and call to the 
_jspService on every script request

What happens if you handle Pool Coonections with a 'java.sql.Connection 
conn' variable declared into the definitions block "<%! %>"?

Happens than if you are donig multitheading and executing the same 
sctipt in parallel you will mix up connections because evey thead is 
executing the same method in parallel and putting a different connection 
into the java.sql.Connection conn class variable.

I don't know if this is a tomcat bug.




FIRMA


Estemensaje se dirige exclusivamente a su destinatario. Contiene 
información *CONFIDENCIAL* sometida a secreto profesional o cuya 
divulgación está prohibida por Ley.
Si ha recibido este mensaje por error, debe saber que su lectura, copia 
y uso están prohibidos.
Le rogamos nos lo comunique inmediatamente por esta misma vía o por 
teléfono 93 600 36 00y proceda a su destrucción.
El correo electrónico vía Internet no permite asegurar la 
confidencialidad de los mensajes que se transmiten ni su integridad o 
correcta recepción.
*TEMPEL S.A.*no asume responsabilidad por estas circunstancias. Si el 
destinatario de este mensaje no consintiera la utilización del correo 
electrónico vía Internet y la grabación de los mensajes, rogamos lo 
ponga en nuestro conocimiento de forma inmediata.
En cumplimiento de la Ley Orgánica 15/1999, de 13 de diciembre, de 
Protección de Datos de Carácter Personal le informamos de que sus datos 
personales y de empresa pasarán a formar parte de un fichero registrado 
ante la Agencia Española de Protección de Datos.
Los datos personales que existen en nuestro poder están protegidos por 
nuestra Política de Seguridad, y no serán compartidos con ninguna otra 
empresa.
Usted puede ejercitar sus derechos de acceso, rectificación, cancelación 
y oposición dirigiéndose por escrito a c/ Cobalto, 4 08907 L'Hospitalet 
de LLobregat (Barcelona).


El 14/12/2011 17:21, Aitor Garcia | Tempel.es escribió:
> Hi,
>
> After three days of research I've found notthing that helps me to 
> solve this problem, it's why I'm trying to get help from the list.
>
> I'm getting connections from dbcp pool in this way:
>
>     /*********************************************************/
>     /* Open a connection to the database                     */
>     /*********************************************************/
>
>
>     // AITOR 13/12/2011
>     // Seems that connections stay active
>     java.sql.Connection conn = null;
>
>     // PreparedStatement prestmt = null;
>     Statement stmt = null;
>     ResultSet res = null;
>
>     /*********************************************************/
>     /* Open a connection to the database                     */
>     /*********************************************************/
>
>     public boolean web_dbConnect()  throws SQLException
>     {
>
>         try
>         {
>             javax.naming.Context initContext = new
>     javax.naming.InitialContext();
>              javax.naming.Context envContext  = (javax.naming.Context)
>     initContext.lookup("java:/comp/env");
>             javax.sql.DataSource datasource = (javax.sql.DataSource)
>     envContext.lookup("jdbc/localpool");
>
>             // get connection from datasource
>             conn = datasource.getConnection();
>
>             // wrap the connection with log4jdbc
>             conn = new net.sf.log4jdbc.ConnectionSpy(conn);
>
>             // now use Connection as normal (but it will be audited by
>     log4jdbc)
>             web_dbLog("Get DB Connection '" + conn + "'");
>
>             /*
>             DatabaseMetaData meta = conn.getMetaData();
>
>             web_dbLog("Driver Name: " + meta.getDriverName());
>             web_dbLog("Driver Version: " + meta.getDriverVersion());
>             web_dbLog("Max Connections: " + meta.getMaxConnections());
>             */
>
>             /*
>             ResultSet res = meta.getTables(null, null, "%", null);
>
>             while (res.next())
>             {
>                 web_dbLog(res.getString(3));
>             }
>             */
>         }
>         catch( javax.naming.NamingException ne )
>         {
>             // throw new RuntimeException( "Unable to aquire data
>     source", ne );
>             web_dbLog("ERROR: Unable to aquire DB Connection from
>     Datasource");
>
>             return (false);
>
>
>         }
>
>
>
>         return (true);
>
>     }
>
>
> Closing connection here:
>
>
>     /*********************************************************/
>     /* Close the connection to the database                     */
>     /*********************************************************/
>
>     public void web_dbClose() throws SQLException
>     {
>         // Never close the database connection, because
>         // it may interfere with other scripts which
>         // share the same connection.
>         web_dbLog("Return DB Conection to pool");
>
>
>
>
>         if(res == null)
>         {
>             web_dbLog("Sorry, ResultSet in null");
>         }
>         else
>         {
>             res.close();
>             res = null;
>
>             web_dbLog("ResultSet closed!");
>         }
>
>
>         if(stmt == null)
>         {
>             web_dbLog("Sorry, Statement in null");
>         }
>         else
>         {
>             stmt.close();
>             stmt = null;
>
>             web_dbLog("Statement closed!");
>         }
>
>         if(conn == null)
>         {
>             web_dbLog("Sorry, Connection in null");
>         }
>         else
>         {
>             conn.close();
>             conn = null;
>
>             web_dbLog("Connection closed!");
>         }
>     }
>
>
> All was working UNTIL AJAX comes. I have an AJAX script that launches 
> different JSP scripts at the same time, and seems that comcat mix the 
> connections:
>
> The .jsp just
>
> 1) Opens connections
> 2) Make a SELECT statement
> 3) Make an UPDATE
> 2) Close a connection
>
> See the code:
>
>
>     String SQL = "";
>
>
>    web_dbConnect();
>
>     HashMap section = new HashMap();
>
>     // Que valor tiene actualmente el menú
>     SQL = "SELECT ... ";
>
>
>
>     section = web_getElem(SQL);
>
>
>
>
>
>     SQL = "UPDATE "...;
>
>
>
>     web_dbUpdate(SQL);
>
>
>
>     web_dbClose();
>
>
>
> Code works well but connections mix, I have installed log4jdbc to see 
> whan happens & the probler arise with the micure of connections into 
> different threads:
>
>     15 [http-bio-8080-exec-4] INFO jdbc.connection - 1. Connection
>     opened 15 [http-bio-8080-exec-4] INFO jdbc.audit - 1.
>     Connection.new Connection returned 16 [http-bio-8080-exec-6] INFO
>     jdbc.connection - 2. Connection opened 17 [http-bio-8080-exec-7]
>     INFO jdbc.connection - 3. Connection opened 17
>     [http-bio-8080-exec-7] INFO jdbc.audit - 3. Connection.new
>     Connection returned 17 [http-bio-8080-exec-6] INFO jdbc.audit - 2.
>     Connection.new Connection returned 17 [http-bio-8080-exec-2] INFO
>     jdbc.connection - 4. Connection opened 17 [http-bio-8080-exec-2]
>     INFO jdbc.audit - 4. Connection.new Connection returned 22
>     [http-bio-8080-exec-7] INFO jdbc.audit - 4. Statement.new
>     Statement returned 22 [http-bio-8080-exec-7] INFO jdbc.audit - 4.
>     Connection.createStatement(1004, 1007) returned
>     net.sf.log4jdbc.StatementSpy@3a0589 22 [http-bio-8080-exec-6] INFO
>     jdbc.audit - 4. Statement.new Statement returned 22
>     [http-bio-8080-exec-7] INFO jdbc.sqlonly - SELECT ... 22
>     [http-bio-8080-exec-4] INFO jdbc.audit - 4. Statement.new
>     Statement returned 22 [http-bio-8080-exec-4] INFO jdbc.audit - 4.
>     Connection.createStatement(1004, 1007) returned
>     net.sf.log4jdbc.StatementSpy@12a2259 23 [http-bio-8080-exec-4]
>     INFO jdbc.sqlonly - SELECT... 22 [http-bio-8080-exec-6] INFO
>     jdbc.audit - 4. Connection.createStatement(1004, 1007) returned
>     net.sf.log4jdbc.StatementSpy@14177f3 23 [http-bio-8080-exec-6]
>     INFO jdbc.sqlonly - SELECT ... 36 [http-bio-8080-exec-7] INFO
>     jdbc.sqltiming - SELECT.... {executed in 13 msec} 42
>     [http-bio-8080-exec-7] INFO jdbc.resultset - 4. ResultSet.new
>     ResultSet returned 42 [http-bio-8080-exec-7] INFO jdbc.audit - 4.
>     Statement.executeQuery(SELECT ... ) returned
>     net.sf.log4jdbc.ResultSetSpy@2a2ae9 42 [http-bio-8080-exec-7] INFO
>     jdbc.resultset - 4. ResultSet.getRow() returned 0 42
>     [http-bio-8080-exec-7] INFO jdbc.resultset - 4. ResultSet.last()
>     returned true 42 [http-bio-8080-exec-7] INFO jdbc.resultset - 4.
>     ResultSet.getRow() returned 0 42 [http-bio-8080-exec-7] INFO
>     jdbc.resultset - 4. ResultSet.beforeFirst() returned 57
>     [http-bio-8080-exec-2] INFO jdbc.audit - 4. Statement.new
>     Statement returned 57 [http-bio-8080-exec-2] INFO jdbc.audit - 4.
>     Connection.createStatement(1004, 1007) returned
>     net.sf.log4jdbc.StatementSpy@1b56848 57 [http-bio-8080-exec-2]
>     INFO jdbc.sqlonly - SELECT.... 60 [http-bio-8080-exec-4] INFO
>     jdbc.sqltiming - SELECT... {executed in 37 msec} 60
>     [http-bio-8080-exec-4] INFO jdbc.resultset - 4. ResultSet.new
>     ResultSet returned 60 [http-bio-8080-exec-4] INFO jdbc.audit - 4.
>     Statement.executeQuery(SELECT ... ) returned
>     net.sf.log4jdbc.ResultSetSpy@1c26db4 60 [http-bio-8080-exec-4]
>     INFO jdbc.resultset - 4. ResultSet.getRow() returned 0 60
>     [http-bio-8080-exec-4] INFO jdbc.resultset - 4. ResultSet.last()
>     returned true 60 [http-bio-8080-exec-4] INFO jdbc.resultset - 4.
>     ResultSet.getRow() returned 0 60 [http-bio-8080-exec-4] INFO
>     jdbc.resultset - 4. ResultSet.beforeFirst() returned 96
>     [http-bio-8080-exec-6] INFO jdbc.sqltiming - SELECT ... {executed
>     in 73 msec} 96 [http-bio-8080-exec-6] INFO jdbc.resultset - 4.
>     ResultSet.new ResultSet returned 96 [http-bio-8080-exec-6] INFO
>     jdbc.audit - 4. Statement.executeQuery(SELECT ...) returned
>     net.sf.log4jdbc.ResultSetSpy@1b0620c 96 [http-bio-8080-exec-6]
>     INFO jdbc.resultset - 4. ResultSet.getRow() returned 0 96
>     [http-bio-8080-exec-6] INFO jdbc.resultset - 4. ResultSet.last()
>     returned true 96 [http-bio-8080-exec-6] INFO jdbc.resultset - 4.
>     ResultSet.getRow() returned 0 96 [http-bio-8080-exec-6] INFO
>     jdbc.resultset - 4. ResultSet.beforeFirst() returned 102
>     [http-bio-8080-exec-4] INFO jdbc.audit - 4. PreparedStatement.new
>     PreparedStatement returned 102 [http-bio-8080-exec-7] INFO
>     jdbc.audit - 4. PreparedStatement.new PreparedStatement returned
>     102 [http-bio-8080-exec-4] INFO jdbc.audit - 4.
>     Connection.prepareStatement(UPDATE ...) returned
>     net.sf.log4jdbc.PreparedStatementSpy@d4a1d3 102
>     [http-bio-8080-exec-7] INFO jdbc.audit - 4.
>     Connection.prepareStatement(UPDATE ...) returned
>     net.sf.log4jdbc.PreparedStatementSpy@1cc3baa 103
>     [http-bio-8080-exec-4] INFO jdbc.sqlonly - UPDATE ... 103
>     [http-bio-8080-exec-7] INFO jdbc.sqlonly - UPDATE .... 133
>     [http-bio-8080-exec-2] INFO jdbc.sqltiming - SELECT ... {executed
>     in 76 msec} 133 [http-bio-8080-exec-2] INFO jdbc.resultset - 4.
>     ResultSet.new ResultSet returned 133 [http-bio-8080-exec-2] INFO
>     jdbc.audit - 4. Statement.executeQuery(SELECT ... ) returned
>     net.sf.log4jdbc.ResultSetSpy@1611aec 133 [http-bio-8080-exec-2]
>     INFO jdbc.resultset - 4. ResultSet.getRow() returned 0 133
>     [http-bio-8080-exec-2] INFO jdbc.resultset - 4. ResultSet.last()
>     returned true 133 [http-bio-8080-exec-2] INFO jdbc.resultset - 4.
>     ResultSet.getRow() returned 0 133 [http-bio-8080-exec-2] INFO
>     jdbc.resultset - 4. ResultSet.beforeFirst() returned 134
>     [http-bio-8080-exec-6] INFO jdbc.audit - 4. PreparedStatement.new
>     PreparedStatement returned 134 [http-bio-8080-exec-6] INFO
>     jdbc.audit - 4. Connection.prepareStatement(UPDATE ...) returned
>     net.sf.log4jdbc.PreparedStatementSpy@2e9c76 135
>     [http-bio-8080-exec-6] INFO jdbc.sqlonly - UPDATE ... 197
>     [http-bio-8080-exec-7] INFO jdbc.sqltiming - UPDATE ... {executed
>     in 93 msec} 197 [http-bio-8080-exec-7] INFO jdbc.audit - 4.
>     PreparedStatement.executeUpdate() returned 1 225
>     [http-bio-8080-exec-8] INFO jdbc.connection - 5. Connection opened
>     225 [http-bio-8080-exec-8] INFO jdbc.audit - 5. Connection.new
>     Connection returned 227 [http-bio-8080-exec-8] INFO jdbc.audit -
>     5. Statement.new Statement returned 227 [http-bio-8080-exec-8]
>     INFO jdbc.audit - 5. Connection.createStatement(1004, 1007)
>     returned net.sf.log4jdbc.StatementSpy@11f2041 227
>     [http-bio-8080-exec-8] INFO jdbc.sqlonly - SELECT ... 249
>     [http-bio-8080-exec-4] INFO jdbc.sqltiming - UPDATE .... {executed
>     in 146 msec} 249 [http-bio-8080-exec-4] INFO jdbc.audit - 4.
>     PreparedStatement.executeUpdate() returned 1 250
>     [http-bio-8080-exec-8] INFO jdbc.sqltiming - SELECT ... {executed
>     in 23 msec} 250 [http-bio-8080-exec-8] INFO jdbc.resultset - 5.
>     ResultSet.new ResultSet returned 250 [http-bio-8080-exec-8] INFO
>     jdbc.audit - 5. Statement.executeQuery(SELECT ... ) returned
>     net.sf.log4jdbc.ResultSetSpy@7e942f 250 [http-bio-8080-exec-8]
>     INFO jdbc.resultset - 5. ResultSet.getRow() returned 0 250
>     [http-bio-8080-exec-8] INFO jdbc.resultset - 5. ResultSet.last()
>     returned true 250 [http-bio-8080-exec-8] INFO jdbc.resultset - 5.
>     ResultSet.getRow() returned 0 250 [http-bio-8080-exec-8] INFO
>     jdbc.resultset - 5. ResultSet.beforeFirst() returned 250
>     [http-bio-8080-exec-7] INFO jdbc.audit - 4.
>     PreparedStatement.close() returned 251 [http-bio-8080-exec-10]
>     INFO jdbc.connection - 6. Connection opened 251
>     [http-bio-8080-exec-10] INFO jdbc.audit - 6. Connection.new
>     Connection returned 252 [http-bio-8080-exec-10] INFO jdbc.audit -
>     6. Statement.new Statement returned 252 [http-bio-8080-exec-10]
>     INFO jdbc.audit - 6. Connection.createStatement(1004, 1007)
>     returned net.sf.log4jdbc.StatementSpy@74ece8 252
>     [http-bio-8080-exec-10] INFO jdbc.sqlonly - SELECT... 261
>     [http-bio-8080-exec-10] INFO jdbc.sqltiming - SELECT ... {executed
>     in 9 msec} 261 [http-bio-8080-exec-10] INFO jdbc.resultset - 6.
>     ResultSet.new ResultSet returned 261 [http-bio-8080-exec-10] INFO
>     jdbc.audit - 6. Statement.executeQuery(SELECT ...) returned
>     net.sf.log4jdbc.ResultSetSpy@165d118 261 [http-bio-8080-exec-10]
>     INFO jdbc.resultset - 6. ResultSet.getRow() returned 0 261
>     [http-bio-8080-exec-10] INFO jdbc.resultset - 6. ResultSet.last()
>     returned true 261 [http-bio-8080-exec-10] INFO jdbc.resultset - 6.
>     ResultSet.getRow() returned 0 261 [http-bio-8080-exec-10] INFO
>     jdbc.resultset - 6. ResultSet.beforeFirst() returned 264
>     [http-bio-8080-exec-10] INFO jdbc.audit - 6. PreparedStatement.new
>     PreparedStatement returned 264 [http-bio-8080-exec-10] INFO
>     jdbc.audit - 6. Connection.prepareStatement(UPDATE ...) returned
>     net.sf.log4jdbc.PreparedStatementSpy@18297fe 264
>     [http-bio-8080-exec-8] INFO jdbc.audit - 5. PreparedStatement.new
>     PreparedStatement returned 264 [http-bio-8080-exec-8] INFO
>     jdbc.audit - 5. Connection.prepareStatement(UPDATE....) returned
>     net.sf.log4jdbc.PreparedStatementSpy@c8aeb3 269
>     [http-bio-8080-exec-7] INFO jdbc.resultset - 5. ResultSet.close()
>     returned 269 [http-bio-8080-exec-10] INFO jdbc.sqlonly - UPDATE
>     .... 278 [http-bio-8080-exec-8] INFO jdbc.sqlonly - UPDATE... 340
>     [http-bio-8080-exec-6] INFO jdbc.sqltiming - UPDATE .. {executed
>     in 205 msec} 340 [http-bio-8080-exec-6] INFO jdbc.audit - 4.
>     PreparedStatement.executeUpdate() returned 1 341
>     [http-bio-8080-exec-2] INFO jdbc.audit - 4. PreparedStatement.new
>     PreparedStatement returned 341 [http-bio-8080-exec-2] INFO
>     jdbc.audit - 4. Connection.prepareStatement(UPDATE ...) returned
>     net.sf.log4jdbc.PreparedStatementSpy@5f634c 342
>     [http-bio-8080-exec-6] INFO jdbc.audit - 4.
>     PreparedStatement.close() returned 343 [http-bio-8080-exec-4] INFO
>     jdbc.audit - 4. PreparedStatement.close() returned 344
>     [http-bio-8080-exec-2] INFO jdbc.sqlonly - UPDATE ... 365
>     [http-bio-8080-exec-2] INFO jdbc.sqltiming - UPDATE ... {executed
>     in 21 msec} 365 [http-bio-8080-exec-2] INFO jdbc.audit - 4.
>     PreparedStatement.executeUpdate() returned 1 367
>     [http-bio-8080-exec-2] INFO jdbc.audit - 4.
>     PreparedStatement.close() returned 428 [http-bio-8080-exec-10]
>     INFO jdbc.sqltiming - UPDATE ...' {executed in 159 msec} 428
>     [http-bio-8080-exec-10] INFO jdbc.audit - 6.
>     PreparedStatement.executeUpdate() returned 1 431
>     [http-bio-8080-exec-7] INFO jdbc.audit - 6. Statement.close()
>     returned 433 [http-bio-8080-exec-7] INFO jdbc.connection - 6.
>     Connection closed 433 [http-bio-8080-exec-7] INFO jdbc.audit - 6.
>     Connection.close() returned 436 [http-bio-8080-exec-10] INFO
>     jdbc.audit - 6. PreparedStatement.close() returned 436
>     [http-bio-8080-exec-8] INFO jdbc.sqltiming - UPDATE ... {executed
>     in 158 msec} 436 [http-bio-8080-exec-8] INFO jdbc.audit - 5.
>     PreparedStatement.executeUpdate() returned 1 439
>     [http-bio-8080-exec-6] INFO jdbc.audit - 6. Statement.close()
>     returned 439 [http-bio-8080-exec-4] INFO jdbc.audit - 6.
>     Statement.close() returned 439 [http-bio-8080-exec-2] INFO
>     jdbc.audit - 6. Statement.close() returned 453
>     [http-bio-8080-exec-8] INFO jdbc.audit - 5.
>     PreparedStatement.close() returned 
>
>
>
> I've tested this into : Centos / Windows Vista
> Tomcat : 7.0 (diferent )
> Java: Jre 1.6.0_16, 1.7.0 & 1.7.2
>
> And happens the same.
>
> Thnks. Any help would be appreciated!
>
>
> -- 
>
> FIRMA
>
>
> Estemensaje se dirige exclusivamente a su destinatario. Contiene 
> información *CONFIDENCIAL* sometida a secreto profesional o cuya 
> divulgación está prohibida por Ley.
> Si ha recibido este mensaje por error, debe saber que su lectura, 
> copia y uso están prohibidos.
> Le rogamos nos lo comunique inmediatamente por esta misma vía o por 
> teléfono 93 600 36 00y proceda a su destrucción.
> El correo electrónico vía Internet no permite asegurar la 
> confidencialidad de los mensajes que se transmiten ni su integridad o 
> correcta recepción.
> *TEMPEL S.A.*no asume responsabilidad por estas circunstancias. Si el 
> destinatario de este mensaje no consintiera la utilización del correo 
> electrónico vía Internet y la grabación de los mensajes, rogamos lo 
> ponga en nuestro conocimiento de forma inmediata.
> En cumplimiento de la Ley Orgánica 15/1999, de 13 de diciembre, de 
> Protección de Datos de Carácter Personal le informamos de que sus 
> datos personales y de empresa pasarán a formar parte de un fichero 
> registrado ante la Agencia Española de Protección de Datos.
> Los datos personales que existen en nuestro poder están protegidos por 
> nuestra Política de Seguridad, y no serán compartidos con ninguna otra 
> empresa.
> Usted puede ejercitar sus derechos de acceso, rectificación, 
> cancelación y oposición dirigiéndose por escrito a c/ Cobalto, 4 08907 
> L'Hospitalet de LLobregat (Barcelona).
>