jdbc进阶

数据库事务
set autocommit=0;
start transaction;
delete from test;
;
;
commit or rollback;

Linkedlist removefirst add
Arraylist

jdbc事务管理

conn = JDBCUtils.getConnection();
conn.setAutoCommit(false);
String sql = "UPDATE account SET money = money-200 WHERE name=‘aaa‘";
pstmt1=conn.prepareStatement(sql);
pstmt1.executeUpdate();
String sql2="UPDATE account SET money = money+200 WHERE name=‘bbb‘";
pstmt2=conn.prepareStatement(sql2);
pstmt2.executeUpdate();
conn.commit();

jdbc连接池
private static LinkedList<Connection> connlist=new LinkedList<Connection>();
c3p0
1代码配置(实例化对象设置属性)
2src下c3p0_config.xml的默认配置
dbcp
InputStream in=TestDBCP.class.getClassLoader().getResourceAsStream("dpcp.properties");

Properties prop=new Properties();
System.out.println(in);
prop.load(in);
DataSource pool=BasicDataSourceFactory.createDataSource(prop);
Connection conn=pool.getConnection();
System.out.println(conn);

相关文章