Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 41355 invoked from network); 22 Jan 2010 01:57:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Jan 2010 01:57:57 -0000 Received: (qmail 1452 invoked by uid 500); 22 Jan 2010 01:57:57 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 1386 invoked by uid 500); 22 Jan 2010 01:57:56 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 1376 invoked by uid 99); 22 Jan 2010 01:57:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jan 2010 01:57:56 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of wangyumi@gmail.com designates 209.85.222.200 as permitted sender) Received: from [209.85.222.200] (HELO mail-pz0-f200.google.com) (209.85.222.200) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jan 2010 01:57:48 +0000 Received: by pzk38 with SMTP id 38so486050pzk.9 for ; Thu, 21 Jan 2010 17:57:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=l+bBQjWFMv928VoWEq6LETbWwcnXz6+bcwZrZpkAA90=; b=q/7cG3Ol92em1iWX3H6PFtU6RNb8a69GiLC0eVveLioEQ2WVxRMf5DEc0e7tdEUroE WrIMJBzYWexsbWNel89zMoWgmx0K2ksHrBW5vhUAiKmYuT6w/epFhhTc87ELAeZ1S4bN YMfH50snk0MdrxSWSZOkh8gHL0Hxtp8qPl/bw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=iMJxg+bTcU5Es6nr51DHJS9EJk518ZY+JbTRqmbL4y1jH4+nojeUy1uVeESRkHzzGx qj+wELsX4uKBKD5518C+Xme9UCKpfjD9kQscKzH8IxD7w5UaxOzbr2BZE3A30kAK8Us5 EQY2k1XYd5FG3KBAj40JQee9gB6hTEp0CDCLE= MIME-Version: 1.0 Received: by 10.143.153.36 with SMTP id f36mr975976wfo.186.1264125446238; Thu, 21 Jan 2010 17:57:26 -0800 (PST) In-Reply-To: <5A46E9B8-9441-4CE8-95DA-5AAF27B1E7D1@SUN.com> References: <5A46E9B8-9441-4CE8-95DA-5AAF27B1E7D1@SUN.com> Date: Fri, 22 Jan 2010 09:57:26 +0800 Message-ID: Subject: Re: How to release db connection into pool? From: wang yu To: users@openjpa.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org 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 wr= ote: > 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.*; > =A0import org.apache.openjpa.persistence.*; > =A0... OpenJPAEntityManager kem =3D OpenJPAPersistence.cast(em); > Connection conn =3D (Connection) kem.getConnection(); > =A0// do JDBC stuff > =A0conn.close(); > > Regards, > > Craig > On Jan 21, 2010, at 1:26 AM, wang yu wrote: > >> Gurus: >> I use OpenJPA 1.2.1 and dbcp: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0> >> =A0value=3D"org.apache.commons.dbcp.BasicDataSource" /> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0> >> =A0value=3D"driverClassName=3Doracle.jdbc.driver.OracleDriver, >> url=3Djdbc:oracle:thin:@localhost:1521:orcl, username=3DXXXX, >> password=3DXXX, maxActive=3D8, maxWait=3D10000, poolPreparedStatements= =3Dtrue" >> /> >> >> And I found the connection pool worked perfect for JPA query. But if I >> use JDBC query like following: >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0OpenJPAEntityManager open_manager =3D Ope= nJPAPersistence >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0.cast(entitiManager); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Connection conn =3D (Connection) >> open_manager.getConnection(); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0java.sql.PreparedStatement PrepStmt =3D n= ull; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0java.sql.ResultSet sqlResults =3D null; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0try { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0PrepStmt =3D connection >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0.prepareStatement("select * from >> tsam.MON_BRIDGE"); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0sqlResults =3D PrepStmt.e= xecuteQuery(); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} catch (SQLException e) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0log.error(e.getMessage())= ; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} finally { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0try { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (sqlRe= sults !=3D null) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0sqlResults.close(); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (PrepS= tmt !=3D null) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0PrepStmt.close(); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} catch (SQLException e) = { >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} >> >> The connection cannot be put into pool and the result is out of db >> connection. >> How should I do? =A0Should I use createNativeQuery(String sql, Class >> resultClass) =A0to 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.Russell@sun.com > P.S. A good JDO? O, Gasp! > >