标签:
1 publicclassTestJdbc { 2 public static void main(String[] args)throwsException { //程序入口,并抛出异常 3 Class.forName("oracle.jdbc.driver.OracleDriver"); //使用类装载器创建一个OracleDriver对象并自动在DriverManager中进行注册 4 Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:horizon","scott","tiger"); //创建一个接口用于连接数据库 5 Statement stmt = conn.createStatement(); //创建一个语句对象装在sql语句 6 ResultSet rs = stmt.executeQuery("select * from dept"); //将返回的结果装在返回集rs中 7 while(rs.next()) { 8 System.out.println(rs.getString("deptno")); //当返回集的游标向下移动的时候打印字段内容 9 } 10 rs.close(); 11 stmt.close(); 12 conn.close(); //关闭接口 13 } 14 }
标签:
原文地址:http://www.cnblogs.com/horizonli/p/5020037.html