日期:2014-05-17 浏览次数:20781 次
package com.oracle.test;
import java.sql.*;
public class TestOracle {
/**
* @param args
*/
//此程序演示对oracle的curd操作
public static void main(String[] args) {
// TODO Auto-generated method stub
//定义我们需要的变量
Connection con=null;
PreparedStatement ps=null;
ResultSet rst=null;
System.out.println("hello world");
try{
//1. 加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("//1. 加载驱动");
//2. 得到连接
con=DriverManager.getConnection("jdbc:oracle:thin@127.0.0.1:1521:orcl","system","12345");
System.out.println("//2. 得到连接");
//3. 创建 preparedstatement 接口对象
ps=con.prepareStatement("select * from lijing");
System.out.println(ps);
//4. 完成查询
rst=ps.executeQuery();
//5,循环输出结果
while(rst.next()){
System.out.println(rst.getInt(1));
System.out.println("hello world");
}
}catch(Exception e){
}finally {
}
}
}
con=DriverManager.getConnection("jdbc:oracle:thin@127.0.0.1:1521:orcl","system","12345");