Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 27195 invoked from network); 3 Sep 2007 12:44:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Sep 2007 12:44:06 -0000 Received: (qmail 43462 invoked by uid 500); 3 Sep 2007 12:43:56 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 43361 invoked by uid 500); 3 Sep 2007 12:43:56 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 43352 invoked by uid 99); 3 Sep 2007 12:43:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Sep 2007 05:43:56 -0700 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [64.233.184.228] (HELO wr-out-0506.google.com) (64.233.184.228) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Sep 2007 12:43:52 +0000 Received: by wr-out-0506.google.com with SMTP id c46so572577wra for ; Mon, 03 Sep 2007 05:43:29 -0700 (PDT) Received: by 10.143.160.1 with SMTP id m1mr225332wfo.1188823408493; Mon, 03 Sep 2007 05:43:28 -0700 (PDT) Received: by 10.142.79.2 with HTTP; Mon, 3 Sep 2007 05:43:27 -0700 (PDT) Message-ID: Date: Mon, 3 Sep 2007 08:43:27 -0400 From: "James Carman" Sender: jcarman@carmanconsulting.com To: "Jakarta Commons Users List" Subject: Re: simple JDBC question In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <86aa493a0709030502k26e770c9hceaf9d115f95ae72@mail.gmail.com> X-Google-Sender-Auth: 8c15087a421e3113 X-Virus-Checked: Checked by ClamAV on apache.org You are essentially throwing away the exception from the driver if it can't set autocommit to false. I'm pretty sure that the MySQL jdbc driver supports that, but you might want to print something in that catch statement to make sure. On 9/3/07, Alessandro Ferrucci wrote: > also I've been stepping through this code in the debugger and right after > the first execute statement I still should not see anything in the DB (not > until I do a commit). But when I step through the first execute and I check > my DB I see the record has been written...I dont get that > > alessandro ferrucci > > On 9/3/07, Alessandro Ferrucci wrote: > > > > Yes I delete all data from it all the time. > > > > alessandro ferrucci > > > > On 9/3/07, ben short wrote: > > > > > > Are you sure that the table is empty before you run the test? > > > > > > On 9/3/07, Alessandro Ferrucci < alessandroferrucci@gmail.com> wrote: > > > > Hi this question is related to DBCP, but I will provide a sample > > > without > > > > DBCP code since I see the same behavior either way. > > > > > > > > I have this very simple class: > > > > > > > > for some reaosn when I debug it in eclipse, and I step through the > > > first > > > > statement I see the record has already been inserted in teh DB when I > > > put > > > > autocommit to false...why is this? Also what should happen in this > > > case is > > > > that the second statement is invalid so it throws an exception and the > > > > connection should rollback both statements but it is not...the first > > > > statement is obviously automatically commited...I cannot find out why > > > this > > > > is not working > > > > > > > > thx > > > > > > > > alessandro ferrucci :) > > > > > > > > import java.sql.Connection; > > > > import java.sql.DriverManager; > > > > import java.sql.SQLException; > > > > import java.sql.Statement; > > > > > > > > import org.junit.Test; > > > > > > > > // > > > > > > > **************************************************************************** > > > > > > > > > > > public class TestJDBC > > > > { > > > > @Test > > > > public void test() > > > > { > > > > Connection conn = null; > > > > try > > > > { > > > > Class.forName ("com.mysql.jdbc.Driver"); > > > > } > > > > catch (ClassNotFoundException ex) > > > > { > > > > System.out.println(ex.getMessage()); > > > > } > > > > try > > > > { > > > > conn = DriverManager > > > > > > > > > > > .getConnection("jdbc:mysql://localhost:3306/photos?user=root&password="); > > > > conn.setAutoCommit(false); > > > > } > > > > catch (SQLException ex) > > > > { > > > > > > > > } > > > > Statement stmt = null; > > > > try > > > > { > > > > stmt = conn.createStatement(); > > > > } > > > > catch (Exception ex) > > > > { > > > > System.out.println(ex.getMessage()); > > > > } > > > > try > > > > { > > > > stmt.execute("insert INTO photostest (id) VALUES (100)"); > > > > stmt = conn.createStatement(); > > > > stmt.execute("insert INTO photostest (id2) VALUES (200)"); > > > > } > > > > catch (Exception ex) > > > > { > > > > System.out.println(ex.getMessage()); > > > > try > > > > { > > > > conn.rollback(); > > > > } > > > > catch (Exception e) > > > > { > > > > System.out.println(ex.getMessage()); > > > > } > > > > } > > > > } > > > > } > > > > > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > > > For additional commands, e-mail: user-help@commons.apache.org > > > > > > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org