Demo MySql Transaction : Transaction : Database SQL JDBC : Java examples (example source code) Organized by topic

Java
C++
PHP
Java Home »  Database SQL JDBC   » [  Transaction  ]  Screenshots 
 



Demo MySql Transaction

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class MainClass {
  public static void main(String[] args) {
    Connection connection = null;
    Statement statement = null;
    try {
      Class.forName("org.gjt.mm.mysql.Driver").newInstance();
      String url = "jdbc:mysql://localhost/hrapp";
      connection = DriverManager.getConnection(url, "username""password");

      statement = connection.createStatement();
      String employees1SQL = "UPDATE employees SET " "num_dependants = 4 "
          "WHERE employee_id = 123456";
      statement.executeUpdate(employees1SQL);
      String employees2SQL = "UPDATE employees SET " "num_dependants = 4 "
          "WHERE employee_id = 123457";
      statement.executeUpdate(employees2SQL);
    catch (Exception e) {
      e.printStackTrace();
    finally {
      if (statement != null) {
        try {
          statement.close();
        catch (SQLException e) {
        }
      }
      if (connection != null) {
        try {
          connection.close();
        catch (SQLException e) {
        }
      }
    }
  }

}

           
       
Related examples in the same category
1.  Test Supports Transactions
2.  Transaction Pairs
3.  Transaction Info
4.  JDBC Transaction
5.  Transaction Pairs 2








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.