Browse Source

删除文件 threadlocaldemo/ThreadLocal_Demo/demo02/src/com/woniu/transfer/dao/AccountDao.java

pull/1/head
马府强 2 years ago
committed by Gitee
parent
commit
70ac6ead32
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
  1. 40
      threadlocaldemo/ThreadLocal_Demo/demo02/src/com/woniu/transfer/dao/AccountDao.java

40
threadlocaldemo/ThreadLocal_Demo/demo02/src/com/woniu/transfer/dao/AccountDao.java

@ -1,40 +0,0 @@
package com.itheima.transfer.dao;
import com.itheima.transfer.utils.JdbcUtils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/*
* 常规方案:
* 1. 方法添加一个参数 conn
* 2. 不能从连接池中获取连接,直接使用参数conn
* 3. 注意: dao层不能释放连接
* */
public class AccountDao {
//转出
public void out(String outUser, int money) throws SQLException {
String sql = "update account set money = money - ? where name = ?";
Connection conn = JdbcUtils.getConnection();
PreparedStatement pstm = conn.prepareStatement(sql);
pstm.setInt(1,money);
pstm.setString(2,outUser);
pstm.executeUpdate();
// JdbcUtils.release(pstm,conn);
}
//转入
public void in(String inUser, int money) throws SQLException {
String sql = "update account set money = money + ? where name = ?";
Connection conn = JdbcUtils.getConnection();
PreparedStatement pstm = conn.prepareStatement(sql);
pstm.setInt(1,money);
pstm.setString(2,inUser);
pstm.executeUpdate();
// JdbcUtils.release(pstm,conn);
}
}
Loading…
Cancel
Save