a JDBC question

Discussion in 'Java' started by Jerry, Aug 1, 2005.

  1. Jerry

    Jerry Guest

    In my code, I want to the following two queries as a trasaction. If any
    of the two queries failed, the database will roll back both queries.How
    to make two queries as one trasaction?

    // will the code below regard query1 and query2 as trasaction?

    query1 = "delete from table1";
    query2 = "insert into table1 values ("a1, "a2);

    statement1.executeQuery(query1);
    statement1.executeQuery(query2);

    conn.commit();

    // If I don't issue a commit() explictly, will the above two queries be
    commited automatically?

    Thanks a lot!
     
    Jerry, Aug 1, 2005
    #1
    1. Advertising

  2. "Jerry" <> wrote:
    > In my code, I want to the following two queries as a trasaction. If any
    > of the two queries failed, the database will roll back both queries.How
    > to make two queries as one trasaction?
    >
    > // will the code below regard query1 and query2 as trasaction?
    >
    > query1 = "delete from table1";
    > query2 = "insert into table1 values ("a1, "a2);
    >
    > statement1.executeQuery(query1);
    > statement1.executeQuery(query2);
    >
    > conn.commit();
    >
    > // If I don't issue a commit() explictly, will the above two queries be
    > commited automatically?
    >
    > Thanks a lot!
    >


    What about reading the javadoc of java.sql.Connection?
    Look at setAutoCommit(boolean)

    --
    "TFritsch$t-online:de".replace(':','.').replace('$','@')
     
    Thomas Fritsch, Aug 2, 2005
    #2
    1. Advertising

  3. Jerry

    steve Guest

    On Tue, 2 Aug 2005 04:40:57 +0800, Jerry wrote
    (in article <>):

    > In my code, I want to the following two queries as a trasaction. If any
    > of the two queries failed, the database will roll back both queries.How
    > to make two queries as one trasaction?
    >
    > // will the code below regard query1 and query2 as trasaction?
    >
    > query1 = "delete from table1";
    > query2 = "insert into table1 values ("a1, "a2);
    >
    > statement1.executeQuery(query1);
    > statement1.executeQuery(query2);
    >
    > conn.commit();
    >
    > // If I don't issue a commit() explictly, will the above two queries be
    > commited automatically?
    >
    > Thanks a lot!
    >


    FFS
    Connection.autoCommit(false);


    read it , understand it.
     
    steve, Aug 8, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keith Wansbrough

    Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver

    Keith Wansbrough, Aug 16, 2004, in forum: Java
    Replies:
    0
    Views:
    802
    Keith Wansbrough
    Aug 16, 2004
  2. Betty
    Replies:
    1
    Views:
    9,932
    Juha Laiho
    May 21, 2005
  3. Jesus M. Salvo Jr.
    Replies:
    2
    Views:
    4,323
    robert
    Feb 11, 2006
  4. Bruce
    Replies:
    4
    Views:
    793
    Bjorn Abelli
    Mar 25, 2006
  5. Lew
    Replies:
    0
    Views:
    552
Loading...

Share This Page