openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wang yu <wangy...@gmail.com>
Subject How to release db connection into pool?
Date Thu, 21 Jan 2010 09:26:33 GMT
Gurus:
I use OpenJPA 1.2.1 and dbcp:
			<property name="openjpa.ConnectionDriverName"
				value="org.apache.commons.dbcp.BasicDataSource" />
			<property name="openjpa.ConnectionProperties"
				value="driverClassName=oracle.jdbc.driver.OracleDriver,
url=jdbc:oracle:thin:@localhost:1521:orcl, username=XXXX,
password=XXX, maxActive=8, maxWait=10000, 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

Mime
View raw message