simpleTransaction - VALUES ('Fred',...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import*; i import java.sql.*; i public class simpleTransaction { p public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (Exception ex) {System.out.println("No driver");} try { t Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/books", "rlent", "abc123"); Statement stmt = conn.createStatement(); int ret=0; conn.setAutoCommit(false); // Do something with the Connection try { ret = stmt.executeUpdate("INSERT INTO authors (firstName, lastName)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: VALUES ('Fred', 'Flinstone')" ); V System.out.println("Transaction completed"); conn.commit(); } catch (Exception ex) { System.out.println("Transaction aborted"); conn.rollback(); } stmt.close(); conn.close(); } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); System.exit(1); } } // main }...
View Full Document

This note was uploaded on 07/14/2011 for the course COP 4610L taught by Professor Staff during the Spring '09 term at University of Central Florida.

Page1 / 2

simpleTransaction - VALUES ('Fred',...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online