【问题标题】:Trying to connect Oracle 10g to execute a query but getting some errors [duplicate]尝试连接 Oracle 10g 以执行查询但出现一些错误 [重复]
【发布时间】:2015-08-15 17:04:38
【问题描述】:
import java.sql.*;  
class OracleCon{  
public static void main(String args[]){  
try{  
//step1 load the driver class  
Class.forName("oracle.jdbc.driver.OracleDriver");  

//step2 create  the connection object  
Connection con=DriverManager.getConnection(  
"jdbc:oracle:thin:@localhost:1521:xe","scott","tiger");  

//step3 create the statement object  
Statement stmt=con.createStatement();  

//step4 execute query  
ResultSet rs=stmt.executeQuery("select * from emp");  
while(rs.next())  
System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  

//step5 close the connection object  
con.close();  

}catch(Exception e){ System.out.println(e);}  

}  
}  

错误是

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

我不知道连接到本地主机。

【问题讨论】:

  • 请在发布问题之前对 SO 进行一些研究。这个问题已经被问过很多次了。

标签: java oracle


【解决方案1】:

错误似乎在您的 JDBC 驱动程序类注册中。 确保您的库中包含driver-jar。也可以参考this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多