Dbutils 的JDBC链接

最近实践周,再次用到了这个Apache的开源工具包就在次对着个方面进行了复习

1.JDBC的基本 操作姿势

2.JDBC的步骤是

1.添加驱动包

Class.forName("oracle.jdbc.driver.OracleDriver");

2.加载驱动包 

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@fwwb-439:1521:home", "scott", "tiger");

3.获取数据库连接

ResultSet rs = conn.prepareStatement("slect * from emp");

4.获取preparedStatement对象

 

5.执行sql

ResultSet rs = ps.executeQuery();

6.获取数据

while(rs.next()){
String no = rs.getString(1);
String name = rs.getString(2);
String job = rs.getString(3);
double sal = rs.getDouble(6);
System.out.println(no+","+name+","+job+","+sal);
}

7、释放资源
rs.close();
ps.close();
conn.close();

posted on 2018-06-20 13:03  JETIME庚  阅读(94)  评论(0编辑  收藏  举报

导航