On 1/4/07, Jose de Castro <[EMAIL PROTECTED]> wrote:
The best balance of performance and reliability will come from using a
database connection pool.

Here are a couple of good ones:

DBCP - http://jakarta.apache.org/commons/dbcp/
c3p0 - http://www.mchange.com/projects/c3p0/index.html



I tried using the tomcat support for this, but I get this exception:

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

Here's my context.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<Context>
  <Resource name="jdbc/sampleDB" auth="Container"
      type="javax.sql.DataSource"
      username="..." password="..."
      driverClassName="org.apache.derby.jdbc.ClientDriver"
      url="jdbc:derby://localhost:1527/myDB"
      maxActive="8"    />
</Context>

Here's the connection code:

                try {
                        InitialContext initCtx = new InitialContext();
                        Context envCtx=(Context)initCtx.lookup("java:comp/env");
                        DataSource ds = 
(DataSource)envCtx.lookup("jdbc/sampleDB"); // fails
                        try {
                                connection = ds.getConnection();
                        } catch (SQLException e) {
                                e.printStackTrace();
                        }
                } catch (NamingException e) {
                        e.printStackTrace();
                }
Amir

Amir Michail wrote:
> On 1/4/07, Amir Michail <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I'm getting this exception:
>>
>> java.sql.SQLException: DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ040,
>> SQLERRMC: Failed to start database 'myDB', see the next exception for
>> details.::SQLSTATE: XJ001Java exception: 'Java heap space:
>> java.lang.OutOfMemoryError'.
>>
>
> Please ignore. I solved the problem.
>
> BTW, how long should a servlet hold on to a db connection? Should it
> open a connection for each request? Or is it sufficient to just open a
> connection once? Does it matter in terms of reliability of the db,
> resource limits, etc.?
>
> Amir
>
>> Any ideas on how to debug this and/or increase the memory available?
>>
>> There isn't much data in the db btw.
>>
>> Amir
>>

Reply via email to