oracle 10g的JDBC连接

(1)在MyEclipse中引入Oracle 10g自带的JDBC包(如“%oracle%\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar”):

右击java项目,选择“Build Path”、“Configure Build Path”,单击“Add External JARs”按钮,选择你的ojdbc14.jar;

(2)开启oracle服务
net start OracleServiceYBNFS

(3)测试代码:

package JDBC;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
public class JDBCtest {
	/**
	 * oracle JDBC连接测试
	 */
	public static void main(String[] args){
		Connection con=null;
		Statement stm=null;
		ResultSet rs=null;
		String sql;
		try{
			sql="select * from z_employ where FSXM like '付%'";
			Class.forName("oracle.jdbc.driver.OracleDriver");
			con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:YBNFS","ybnfs","byybnetfs");
			stm=con.createStatement();
			rs=stm.executeQuery(sql);
			System.out.println("rs="+rs.toString());
                   while(rs.next()){
                        System.out.println(rs.getString("FSXM")+"\t"+rs.getString("FSSFZH")+"\t"+rs.getString("FSJTDZ"));
                    }
                  }catch(ClassNotFoundException e){
			e.printStackTrace();
		  }catch(SQLException e){
			System.out.println("发生了异常:"+e.getMessage());
		  }finally{
			try{
				if(rs!=null)
					rs.close();
				if(stm!=null)
					stm.close();
				if(con!=null)
					con.close();
			}catch(SQLException e){
				e.printStackTrace();
			}
		}
	}
}

run as Java application.

rs=oracle.jdbc.driver.OracleResultSetImpl@5e5a50
付煜    000000000103293898    三(11)
付文萱    3********************    null
付殊    3********************    三(12)
付晓    3********************    三(15)
付悦    3********************    二(13)


没有更多推荐了,返回首页