Re: How to release db connection into pool?

2010-01-21 Thread Craig L Russell

Thanks for using OpenJPA and the users alias. Good luck.

Craig

On Jan 21, 2010, at 7:35 PM, wang yu wrote:


Craig,
I have tested it. It's cool!
The db connection will be returned into pool and I can reuse the
JPAEntityManager!
Thanks again.

Regards,
Yu Wang

On Fri, Jan 22, 2010 at 9:57 AM, wang yu  wrote:

Craig:
Thank you for your quick response.
If I close it, the connection will be returned into pool or just  
destroyed?


Regards,
Yu Wang

On Thu, Jan 21, 2010 at 8:56 PM, Craig L Russell > wrote:

Hi Yu Wang,

You need to tell OpenJPA that you're not using the Connection any  
more by

calling close(). See this Example 4.4 in the user's manual:

import java.sql.*;
 import org.apache.openjpa.persistence.*;
 ... OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
Connection conn = (Connection) kem.getConnection();
 // do JDBC stuff
 conn.close();

Regards,

Craig
On Jan 21, 2010, at 1:26 AM, wang yu wrote:


Gurus:
I use OpenJPA 1.2.1 and dbcp:
   name="openjpa.ConnectionDriverName"


 value="org.apache.commons.dbcp.BasicDataSource" />
   name="openjpa.ConnectionProperties"


 value="driverClassName=oracle.jdbc.driver.OracleDriver,
url=jdbc:oracle:thin:@localhost:1521:orcl, username=,
password=XXX, maxActive=8, maxWait=1,  
poolPreparedStatements=true"

/>

And I found the connection pool worked perfect for JPA query. But  
if I

use JDBC query like following:
   OpenJPAEntityManager open_manager =  
OpenJPAPersistence

   .cast(entitiManager);
   Connection conn = (Connection)
open_manager.getConnection();
   java.sql.PreparedStatement PrepStmt = null;
   java.sql.ResultSet sqlResults = null;
   try {
   PrepStmt = connection
   .prepareStatement("select  
* from

tsam.MON_BRIDGE");
   sqlResults = PrepStmt.executeQuery();
   } catch (SQLException e) {
   log.error(e.getMessage());
   } finally {
   try {
   if (sqlResults != null)
   sqlResults.close();
   if (PrepStmt != null)
   PrepStmt.close();
   } catch (SQLException e) {

   }
   }

The connection cannot be put into pool and the result is out of db
connection.
How should I do?  Should I use createNativeQuery(String sql, Class
resultClass)  to query with native sql?


Regards,
Yu Wang


Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:craig.russ...@sun.com
P.S. A good JDO? O, Gasp!






Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:craig.russ...@sun.com
P.S. A good JDO? O, Gasp!



Re: How to release db connection into pool?

2010-01-21 Thread wang yu
Craig,
 I have tested it. It's cool!
The db connection will be returned into pool and I can reuse the
JPAEntityManager!
Thanks again.

Regards,
Yu Wang

On Fri, Jan 22, 2010 at 9:57 AM, wang yu  wrote:
> Craig:
> Thank you for your quick response.
> If I close it, the connection will be returned into pool or just destroyed?
>
> Regards,
> Yu Wang
>
> On Thu, Jan 21, 2010 at 8:56 PM, Craig L Russell  
> wrote:
>> Hi Yu Wang,
>>
>> You need to tell OpenJPA that you're not using the Connection any more by
>> calling close(). See this Example 4.4 in the user's manual:
>>
>> import java.sql.*;
>>  import org.apache.openjpa.persistence.*;
>>  ... OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
>> Connection conn = (Connection) kem.getConnection();
>>  // do JDBC stuff
>>  conn.close();
>>
>> Regards,
>>
>> Craig
>> On Jan 21, 2010, at 1:26 AM, wang yu wrote:
>>
>>> Gurus:
>>> I use OpenJPA 1.2.1 and dbcp:
>>>                        >>
>>>  value="org.apache.commons.dbcp.BasicDataSource" />
>>>                        >>
>>>  value="driverClassName=oracle.jdbc.driver.OracleDriver,
>>> url=jdbc:oracle:thin:@localhost:1521:orcl, username=,
>>> password=XXX, maxActive=8, maxWait=1, poolPreparedStatements=true"
>>> />
>>>
>>> And I found the connection pool worked perfect for JPA query. But if I
>>> use JDBC query like following:
>>>                OpenJPAEntityManager open_manager = OpenJPAPersistence
>>>                                        .cast(entitiManager);
>>>                Connection conn = (Connection)
>>> open_manager.getConnection();
>>>                java.sql.PreparedStatement PrepStmt = null;
>>>                java.sql.ResultSet sqlResults = null;
>>>                try {
>>>                        PrepStmt = connection
>>>                                        .prepareStatement("select * from
>>> tsam.MON_BRIDGE");
>>>                        sqlResults = PrepStmt.executeQuery();
>>>                } catch (SQLException e) {
>>>                        log.error(e.getMessage());
>>>                } finally {
>>>                        try {
>>>                                if (sqlResults != null)
>>>                                        sqlResults.close();
>>>                                if (PrepStmt != null)
>>>                                        PrepStmt.close();
>>>                        } catch (SQLException e) {
>>>
>>>                        }
>>>                }
>>>
>>> The connection cannot be put into pool and the result is out of db
>>> connection.
>>> How should I do?  Should I use createNativeQuery(String sql, Class
>>> resultClass)  to query with native sql?
>>>
>>>
>>> Regards,
>>> Yu Wang
>>
>> Craig L Russell
>> Architect, Sun Java Enterprise System http://db.apache.org/jdo
>> 408 276-5638 mailto:craig.russ...@sun.com
>> P.S. A good JDO? O, Gasp!
>>
>>
>


Re: How to release db connection into pool?

2010-01-21 Thread wang yu
Craig:
Thank you for your quick response.
If I close it, the connection will be returned into pool or just destroyed?

Regards,
Yu Wang

On Thu, Jan 21, 2010 at 8:56 PM, Craig L Russell  wrote:
> Hi Yu Wang,
>
> You need to tell OpenJPA that you're not using the Connection any more by
> calling close(). See this Example 4.4 in the user's manual:
>
> import java.sql.*;
>  import org.apache.openjpa.persistence.*;
>  ... OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
> Connection conn = (Connection) kem.getConnection();
>  // do JDBC stuff
>  conn.close();
>
> Regards,
>
> Craig
> On Jan 21, 2010, at 1:26 AM, wang yu wrote:
>
>> Gurus:
>> I use OpenJPA 1.2.1 and dbcp:
>>                        >
>>  value="org.apache.commons.dbcp.BasicDataSource" />
>>                        >
>>  value="driverClassName=oracle.jdbc.driver.OracleDriver,
>> url=jdbc:oracle:thin:@localhost:1521:orcl, username=,
>> password=XXX, maxActive=8, maxWait=1, poolPreparedStatements=true"
>> />
>>
>> And I found the connection pool worked perfect for JPA query. But if I
>> use JDBC query like following:
>>                OpenJPAEntityManager open_manager = OpenJPAPersistence
>>                                        .cast(entitiManager);
>>                Connection conn = (Connection)
>> open_manager.getConnection();
>>                java.sql.PreparedStatement PrepStmt = null;
>>                java.sql.ResultSet sqlResults = null;
>>                try {
>>                        PrepStmt = connection
>>                                        .prepareStatement("select * from
>> tsam.MON_BRIDGE");
>>                        sqlResults = PrepStmt.executeQuery();
>>                } catch (SQLException e) {
>>                        log.error(e.getMessage());
>>                } finally {
>>                        try {
>>                                if (sqlResults != null)
>>                                        sqlResults.close();
>>                                if (PrepStmt != null)
>>                                        PrepStmt.close();
>>                        } catch (SQLException e) {
>>
>>                        }
>>                }
>>
>> The connection cannot be put into pool and the result is out of db
>> connection.
>> How should I do?  Should I use createNativeQuery(String sql, Class
>> resultClass)  to query with native sql?
>>
>>
>> Regards,
>> Yu Wang
>
> Craig L Russell
> Architect, Sun Java Enterprise System http://db.apache.org/jdo
> 408 276-5638 mailto:craig.russ...@sun.com
> P.S. A good JDO? O, Gasp!
>
>


Re: How to release db connection into pool?

2010-01-21 Thread Craig L Russell

Hi Yu Wang,

You need to tell OpenJPA that you're not using the Connection any more  
by calling close(). See this Example 4.4 in the user's manual:


import java.sql.*;
 import org.apache.openjpa.persistence.*;
 ... OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
Connection conn = (Connection) kem.getConnection();
 // do JDBC stuff
 conn.close();

Regards,

Craig
On Jan 21, 2010, at 1:26 AM, wang yu wrote:


Gurus:
I use OpenJPA 1.2.1 and dbcp:



And I found the connection pool worked perfect for JPA query. But if I
use JDBC query like following:
OpenJPAEntityManager open_manager = OpenJPAPersistence
.cast(entitiManager);
Connection conn = (Connection) open_manager.getConnection();
java.sql.PreparedStatement PrepStmt = null;
java.sql.ResultSet sqlResults = null;
try {
PrepStmt = connection
.prepareStatement("select * from 
tsam.MON_BRIDGE");
sqlResults = PrepStmt.executeQuery();
} catch (SQLException e) {
log.error(e.getMessage());
} finally {
try {
if (sqlResults != null)
sqlResults.close();
if (PrepStmt != null)
PrepStmt.close();
} catch (SQLException e) {

}
}

The connection cannot be put into pool and the result is out of db  
connection.

How should I do?  Should I use createNativeQuery(String sql, Class
resultClass)  to query with native sql?


Regards,
Yu Wang


Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:craig.russ...@sun.com
P.S. A good JDO? O, Gasp!



How to release db connection into pool?

2010-01-21 Thread wang yu
Gurus:
I use OpenJPA 1.2.1 and dbcp:



And I found the connection pool worked perfect for JPA query. But if I
use JDBC query like following:
OpenJPAEntityManager open_manager = OpenJPAPersistence
.cast(entitiManager);
Connection conn = (Connection) open_manager.getConnection();
java.sql.PreparedStatement PrepStmt = null;
java.sql.ResultSet sqlResults = null;
try {
PrepStmt = connection
.prepareStatement("select * from 
tsam.MON_BRIDGE");
sqlResults = PrepStmt.executeQuery();
} catch (SQLException e) {
log.error(e.getMessage());
} finally {
try {
if (sqlResults != null)
sqlResults.close();
if (PrepStmt != null)
PrepStmt.close();
} catch (SQLException e) {

}
}

The connection cannot be put into pool and the result is out of db connection.
How should I do?  Should I use createNativeQuery(String sql, Class
resultClass)  to query with native sql?


Regards,
Yu Wang