java dao 继承扩展_继承jdbcDaoSupport的方式实现(增删改查)

1 packagecom.xdl.impl;2

3 importjava.util.List;4

5 importjavax.annotation.Resource;6 importjavax.sql.DataSource;7

8 importorg.springframework.dao.DataAccessException;9 importorg.springframework.jdbc.core.support.JdbcDaoSupport;10 importorg.springframework.stereotype.Repository;11

12 importcom.sun.org.apache.bcel.internal.generic.RET;13 importcom.xdl.bean.XdlBankAccount;14 importcom.xdl.dao.XdlBankAccountDao;15 importcom.xdl.mapper.XdlBankAccountMapper;16

17 @Repository("bankDao")18 public class XdlBankAccountDaoOracleImpl extends JdbcDaoSupport implementsXdlBankAccountDao {19 @Resource(name = "dataSource")20 public voidsetMyDataSource(DataSource dataSource) {21 //赋值给父类

22 super.setDataSource(dataSource);23 }24

25 //根据银行账户acc_no查询银行账户对象

26 @Override27 publicXdlBankAccount getBankAccountByAccNo(String acc_no) {28 String sql = "select * from xdl_bank_account where acc_no = ?";29 //return super.getJdbcTemplate().queryForObject(sql, requiredType, acc_no);

30 try{31 return super.getJdbcTemplate().queryForObject(sql, newXdlBankAccountMapper(), acc_no);32 } catch(DataAccessException e) {33 e.printStackTrace();34 }35 return null;36 /**

37 * Spring Dao框架没有做吧结果集翻译成对象过程38 */

39 }40

41 //根据id查询银行账户对象

42 /*

43 * @Override public XdlBankAccount getBanAccountByAccId(int id) { String sql =44 * "select * from xdl_bank_account where id = ?"; try { return45 * super.getJdbcTemplate().queryForObject(sql, new XdlBankAccountMapper(), id);46 * } catch (DataAccessException e) { e.printStackTrace(); } return null; }47 */

48 //根据id查询银行账户对象

49 @Override50 public XdlBankAccount getBanAccountByAccId(intid) {51 String sql = "select * from xdl_bank_account where id = ?";52 List accounts = super.getJdbcTemplate().query(sql, newXdlBankAccountMapper(), id);53 return accounts.isEmpty() ? null : accounts.get(0);54 }55

56 //查询所有的银行账户信息

57 @Override58 public ListgetBankAccountAll() {59 String sql = "select * from xdl_bank_account";60 return super.getJdbcTemplate().query(sql, newXdlBankAccountMapper());61 }62

63 //更新数据

64 @Override65 public intupdateBankAccount(XdlBankAccount account) {66 String sql = "update xdl_bank_account set acc_password = ?,acc_money = ? where id = ? and acc_no = ?";67 return super.getJdbcTemplate().update(sql, account.getAcc_password(), account.getAcc_money(), account.getId(),68 account.getAcc_no());69 }70

71 //根据id删除银行账户

72 @Override73 public intdeleteBankAccount(XdlBankAccount account) {74 String sql = "delete from xdl_bank_account where id = ?";75 try{76 return super.getJdbcTemplate().update(sql, account.getId());77 } catch(DataAccessException e) {78 e.printStackTrace();79 }80 return 0;81 }82

83 //向银行表中插入数据

84 @Override85 public intinsertBankAccount(XdlBankAccount account) {86 String sql = "insert into xdl_bank_account values (xdl_bank_account_id_seq.nextval,?,?,?)";87 try{88 return super.getJdbcTemplate().update(sql, account.getAcc_no(), account.getAcc_password(),89 account.getAcc_money());90 } catch(DataAccessException e) {91 e.printStackTrace();92 }93 return 0;94 }95 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值