oracle驱动加载

  利用java连接oracle数据库的时候报错:

  java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

  错误位置为: Class.forName("oracle.jdbc.driver.OracleDriver");

 

import java.sql.*;

public class Oracleconnect {

	public static void main(String[] args)  {
		// TODO Auto-generated method stub
		  ResultSet rs = null;
		  Statement stmt = null;
		  Connection conn = null;
		  System.out.println("数据库开始加载");
		  try {
		   Class.forName("oracle.jdbc.driver.OracleDriver");
		   System.out.println("数据库加载成功");
		   //new oracle.jdbc.driver.OracleDriver();
		   conn = DriverManager.getConnection("jdbc:oracle:thin:@10.213.54.18:1521:bdspoc", "scott","tiger");
		   //conn = DriverManager.getConnection("jdbc:oracle:thin:@hncs", "scott","tiger");
		   stmt = conn.createStatement();
		   rs = stmt.executeQuery("select * from emp");
		   while(rs.next()) {
			   System.out.print(rs.getString("deptno"));
			   System.out.print("\t|"+rs.getString("ename"));
		       System.out.println("\t|"+rs.getString("empno"));
		   }
		  } catch (ClassNotFoundException e) {
		   e.printStackTrace();
		  } catch (SQLException e) {
		   e.printStackTrace();
		  } finally {
		   try {
		    if(rs != null) {
		     rs.close();
		     rs = null;
		     System.out.println("rs执行完毕");
		    }
		    if(stmt != null) {
		     stmt.close();
		     stmt = null;
		    }
		    if(conn != null) {
		     conn.close();
		     conn = null;
		    }
		   } catch (SQLException e) {
		    e.printStackTrace();
		   }
		  }
		 }		
	}


oracle驱动加载_第1张图片

添加Oracle连接驱动,右键工程名,Build Path --》Add Libraries --》User Libraries --》 User Libraries --》Import  

目录一般为:OralceHome\jdbc\lib  下的ojdbc6.jar   添加该jar包即可。

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(oracle驱动加载)