用myeclipse8.5连接oracle时出现如下提示是怎么回事?
出现:“java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver。”...
出现:“java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver。”
展开
1个回答
展开全部
(1)扒粗在MyEclipse中引入Oracle 11g自带的JDBC包(如“G:\app\welcome\product\11.1.0\db_1\jdbc\lib\ojdbc6.jar”):右击java项目,选择“Build Path”、“Configure Build Path”,单击“Add External JARs”按钮,选择你的ojdbc6.jar;
(2)开户Oracle服务;
(3)编写测试代薯此好码:
import java.sql.*;
public class TestOracle {
public static void main(String[] args) {
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM scott.emp");
while(rs.next()){
System.out.println(rs.getInt(1) + "\t" + rs.getString(2));
}
}catch(Exception err){
System.out.println(err.toString());
}
}
}
(数铅4)运行Java程序:
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
7900 JAMES
7902 FORD
7934 MILLER
如果你的JDK版本太低或太高,但不能用ojdbc6.jar,要用ojdbc5.jar或ojdbc6_g.jar。
(2)开户Oracle服务;
(3)编写测试代薯此好码:
import java.sql.*;
public class TestOracle {
public static void main(String[] args) {
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM scott.emp");
while(rs.next()){
System.out.println(rs.getInt(1) + "\t" + rs.getString(2));
}
}catch(Exception err){
System.out.println(err.toString());
}
}
}
(数铅4)运行Java程序:
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
7900 JAMES
7902 FORD
7934 MILLER
如果你的JDK版本太低或太高,但不能用ojdbc6.jar,要用ojdbc5.jar或ojdbc6_g.jar。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询