Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 13721 invoked from network); 17 Apr 2008 02:32:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Apr 2008 02:32:00 -0000 Received: (qmail 13986 invoked by uid 500); 17 Apr 2008 02:31:59 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 13974 invoked by uid 500); 17 Apr 2008 02:31:59 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 13960 invoked by uid 99); 17 Apr 2008 02:31:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Apr 2008 19:31:59 -0700 X-ASF-Spam-Status: No, hits=2.6 required=10.0 tests=DNS_FROM_OPENWHOIS,SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Apr 2008 02:31:04 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1JmJuG-00089L-Ky for user-java@ibatis.apache.org; Wed, 16 Apr 2008 19:31:24 -0700 Message-ID: <16737591.post@talk.nabble.com> Date: Wed, 16 Apr 2008 19:31:24 -0700 (PDT) From: nepalon To: user-java@ibatis.apache.org Subject: Re: Problem in resultMap:Cause: java.sql.SQLException: Invalid state, the ResultSet object is closed In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: inepalon@163.com References: <16624071.post@talk.nabble.com> <16645060.post@talk.nabble.com> <16656703.post@talk.nabble.com> <16695510.post@talk.nabble.com> <16715819.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org I have tried the code and it work well: Connection cn1 = null; PreparedStatement pst1 = null; PreparedStatement pst2 = null; ResultSet rs1 = null; ResultSet rs2 = null; DataSource ds = (BasicDataSource)ctx.getBean("cmsDbcpDataSource"); try { cn1 = ds.getConnection(); pst1 = cn1.prepareStatement("select fid, fname, fcategoryid from t_softwares"); rs1 = pst1.executeQuery(); while(rs1.next()) { System.out.println("software:" + rs1.getString(2)); pst2 = cn1.prepareStatement("select fid, fname from t_categories where fid=?"); pst2.setInt(1, rs1.getInt(3)); rs2 = pst2.executeQuery(); if(rs2.next()) { System.out.println("category:" + rs2.getString(2)); } rs2.close(); pst2.close(); } rs1.close(); pst1.close(); cn1.close(); } catch(Exception e) { e.printStackTrace(); assertTrue(false); } Jeff Butler-2 wrote: > > Your JDBC code does not match what iBATIS is doing. Try this: > > try { > cn = ds.getConnection(); > pst1 = cn.prepareStatement("select * from t_softwares"); > rs1 = pst1.executeQuery(); > while(rs1.next()) { > System.out.println("software:" + rs1.getString(1)); > pst2 = cn.prepareStatement("select * from t_categories"); > rs2 = pst2.executeQuery(); > while(rs2.next()) { > System.out.println("category:" + rs2.getString(1)); > } > rs2.close(); > pst2.close(); > } > rs1.close(); > pst1.close(); > } > Jeff Butler > > > On Tue, Apr 15, 2008 at 10:36 PM, nepalon wrote: > >> >> I try the code and it work well.At first, I get Connection using >> DriverManager and work well.I think the bug maybe cause by DataSource >> that >> return Connection from pool,so I try to get Connection using >> DataSource,but >> it work well too.So I still believe the exception causing by iBatis. >> >> Connection cn = null; >> PreparedStatement pst1 = null; >> PreparedStatement pst2 = null; >> ResultSet rs1 = null; >> ResultSet rs2 = null; >> DataSource ds = >> (BasicDataSource)ctx.getBean("cmsDbcpDataSource"); >> >> try >> { >> // >> Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance(); >> // cn = >> >> DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/macconverter", >> "sa", "iloveyou"); >> cn = ds.getConnection(); >> pst1 = cn.prepareStatement("select * from t_softwares"); >> rs1 = pst1.executeQuery(); >> while(rs1.next()) >> { >> System.out.println("software:" + >> rs1.getString(1)); >> } >> pst2 = cn.prepareStatement("select * from t_categories"); >> rs2 = pst2.executeQuery(); >> while(rs2.next()) >> { >> System.out.println("category:" + >> rs2.getString(1)); >> } >> } >> catch(Exception e) >> { >> e.printStackTrace(); >> assertTrue(false); >> } >> finally >> { >> try { >> rs1.close(); >> rs2.close(); >> pst1.close(); >> pst2.close(); >> cn.close(); >> } >> catch (SQLException e) >> { >> } >> } >> >> Larry Meadors wrote: >> > >> > Google for "sql 2005 HY010 jdbc -db2", and you'll get more info - it >> > looks like you're not the first person to get this error, but I didn't >> > see anything that led me to believe that this is a bug in iBATIS - >> > more likely an issue with the driver, possibly configuration. >> > >> > Try simplifying the mapped statement and/or doing the query with JDBC >> > instead and see what happens. >> > >> > Larry >> > >> > >> > On Mon, Apr 14, 2008 at 11:46 PM, nepalon wrote: >> >> >> >> I am sure my DB is configured to allow more than one ResultSet >> open.As >> >> you >> >> see in the above code, the code CategoryModel model = >> >> categoryDao.getCategoryById(273) I code can work well.The code will >> load >> >> the >> >> category object the id is 273 and its parent category object whick >> the >> >> id is >> >> 270.In this code,more than one ResultSet was open. >> >> >> >> >> >> >> >> >> >> Jeff Butler-2 wrote: >> >> > >> >> > I once had a similar problem with DB2. The problem was that the DB >> >> was >> >> > configured to allow only one open ResultSet per connection. >> >> > >> >> > With your query, you will have more than one open ResultSet - so >> make >> >> sure >> >> > your DB is configured to allow this. >> >> > >> >> > Jeff Butler >> >> > >> >> > On Sat, Apr 12, 2008 at 10:47 PM, nepalon wrote: >> >> > >> >> >> >> >> >> The DB i using is SQL Server2005.The error string(HY010) means >> >> "Invalid >> >> >> state, the ResultSet object is closed".Somebody says this error >> cause >> >> by >> >> >> using miscrosoft sql server driver,but I using jtds as my dirver. >> >> >> >> >> >> Larry Meadors wrote: >> >> >> > >> >> >> > This looks like a DB2 issue, you may want to search for that >> error >> >> >> > string (HY010), I think that's probably going to get you a >> solution >> >> >> > quickest. >> >> >> > >> >> >> > Larry >> >> >> > >> >> >> > >> >> >> >> >> >> -- >> >> >> View this message in context: >> >> >> >> >> >> http://www.nabble.com/Problem-in-resultMap%3ACause%3A-java.sql.SQLException%3A-Invalid-state%2C-the-ResultSet-object-is-closed-tp16624071p16656703.html >> >> >> Sent from the iBATIS - User - Java mailing list archive at >> >> Nabble.com. >> >> >> >> >> >> >> >> > >> >> > >> >> >> >> -- >> >> View this message in context: >> >> >> http://www.nabble.com/Problem-in-resultMap%3ACause%3A-java.sql.SQLException%3A-Invalid-state%2C-the-ResultSet-object-is-closed-tp16624071p16695510.html >> >> >> >> >> >> Sent from the iBATIS - User - Java mailing list archive at Nabble.com. >> >> >> >> >> > >> > >> >> -- >> View this message in context: >> http://www.nabble.com/Problem-in-resultMap%3ACause%3A-java.sql.SQLException%3A-Invalid-state%2C-the-ResultSet-object-is-closed-tp16624071p16715819.html >> Sent from the iBATIS - User - Java mailing list archive at Nabble.com. >> >> > > -- View this message in context: http://www.nabble.com/Problem-in-resultMap%3ACause%3A-java.sql.SQLException%3A-Invalid-state%2C-the-ResultSet-object-is-closed-tp16624071p16737591.html Sent from the iBATIS - User - Java mailing list archive at Nabble.com.