Hi guys,

Maybe some of you can help me out here, I'm trying to perform a transaction
with my db (SQL Server 7) and was wondering if this is the rough way to go
about it. Has anyone written code to do this?

Connection con = null;

con = myBroker.getConnection();
Statement statement = null, statement2 = null;

try {
        con.setAutoCommit(false);

        statement = con.createStatement();
        statement2 = con.createStatement();

        ResultSet rs = statement.executeQuery("SELECT MAX(ID) as M FROM users");

        while ( rs.next() ) {
                statement2.executeUpdate("INSERT INTO Users(ID, Username) VALUES(" +
rs.getInt("M") + ", 'fred'");
        }

        con.commit();
        con.setAutoCommit(true);
}
catch (SQLException e2) {
        out.println("SQL exception." + e2.toString()    );
}
finally {
        try{if(statement != null) {statement.close();}} catch(SQLException e1){};
        myBroker.freeConnection(con);  // Release connection back to pool
}


Is this looking right? I can't get it to work.

Cheers,
Mike

 __
|  | The BookmarkBox
|  | http://www.bookmarkbox.com
|/\| Manage and share your bookmarks online!

Have you seen our new forums? http://www.bookmarkbox.com/ubbcgi
Share your bookmarking with others and get helpful tips!

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to