public class JdbcDao extends JdbcDaoSupport { @SuppressWarnings("rawtypes") public List getTables() { List result = super.getJdbcTemplate().query( "select username, user_id from dba_users where account_status = ?", new String[]{"OPEN"}, new ColumnMapRowMapper(){ @Override protected String getColumnKey(String columnName) { //不同数据库键值始终为小写 return super.getColumnKey(columnName).toLowerCase(); } }); return result; } public static void main(String[] args) { /*1、创建DAO*/ JdbcDao dao = new JdbcDao(); /*2、为DAO设置数据源*/ DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver"); dataSource.setUrl("jdbc:oracle:thin:@127.0.0.1:1521:orcl"); dataSource.setUsername("BMS2044"); dataSource.setPassword("BMS2044"); dao.setDataSource(dataSource); /*3、调用DAO方法*/ System.out.println(dao.getTables()); } }
时间: 2024-10-30 01:43:11