commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alessandro Ferrucci" <alessandroferru...@gmail.com>
Subject Re: simple JDBC question
Date Mon, 03 Sep 2007 12:39:01 GMT
No I think my code in that respect is fine...I create the statement then
execute it.  I know that I re-create the statement again after the first
execution but I put that in there just to see what it would give me, I didnt
see any change in behavior.

alessandro ferrucci :)

On 9/3/07, Kantartzis Vasileios <Vasileios.Kantartzis@nc3a.nato.int> wrote:
>
> I think if memory serves me right that the create statement should proceed
> the execution statement in your code you try to execute a sttement that has
> not been created.
>
>
> V.(Billy) Kantartzis
> Surveillance & Reconnaissance Resource Centre
> Command & Control Systems
> T:+31(0)70374-3706
> F: +31(0)70374-3079
> E:vasileios.kantartzis@nc3a.nato.int
>
>
>
> -----Original Message-----
> From: Alessandro Ferrucci [mailto:alessandroferrucci@gmail.com]
> Sent: 03 September 2007 13:39
> To: user@commons.apache.org
> Subject: simple JDBC question
>
> 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
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message