用了JDBC后接着学习Dbutils连接数据库
1.添加驱动包
Class.forName("oracle.jdbc.driver.OracleDriver");
2.获取数据库连接
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@fwwb-439:1521:home", "scott", "tiger");
3.DButils连接
QueryRunner runner = new QueryRunner();
4.执行SQL
List<Emp> list = runner.query(conn,"select * from emp",new BeanListHandler<Emp>(Emp.class));
循环遍历
for(int i=0;i<list.size();i++){
Emp emp = list.get(i);
System.out.println(emp.getEmpno()+","+emp.getEname()+","+emp.getJob()+","+emp.getSal());
}