随笔-211  评论-26  文章-8  trackbacks-0

/**********************************************************
Copyright (C),2006-5-8, fuzhou  USTB.
All rights reserved.
Filename: InnoDB.java
Author: 黄**
Version 1.0
Date:2006-5-8
Description:测试支持事务处理的驱动程序,com.mysql.jdbc.Driver支持,而org.gjt.mm.mysql.Driver不支持
mm.mysql-2.0.4-bin.jar用org.gjt.mm.mysql.Driver
mysql-connector-java-3.2.0-alpha-bin.jar用com.mysql.jdbc.Driver
History:
***********************************************************/
import java.sql.*;

public class InnoDB {
 public static void main(String args[]) throws Exception
 {
  Inn();
    } 
 public static void Inn(){
 try
 {
 Class.forName("com.mysql.jdbc.Driver").newInstance();
 Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1/lib","root","");
 boolean autoCommit=con.getAutoCommit();
 con.setAutoCommit(false);
 Statement stmt=con.createStatement();
 for(int i=0;i<5;i++)
 {
 String str="insert into game values('test',100,20.0)";
 String condition=new String(str.getBytes("gb2312"),"8859_1");
 stmt.addBatch(condition);
 }
 stmt.executeBatch();
 con.commit();
 con.setAutoCommit(autoCommit);

 ResultSet rs=stmt.executeQuery("SELECT * FROM GAME");
 while(rs.next())
 {
 System.out.println(rs.getString("name")+""+rs.getInt("account"));
 }

 rs.close();
 stmt.close();
 con.close();
 }
 catch(Exception e)
 {
 System.out.println(e);
 }
 }
}

posted on 2006-05-08 17:56 dragon 阅读(54) 评论(0)  编辑  收藏 所属分类: java