尝试连接Oracle 10g以执行查询但遇到一些错误

时间:2015-08-15 17:04:38

标签: java oracle

2 * texelHeight

,错误是

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);}  

}  
}  

我不知道连接到localhost。

1 个答案:

答案 0 :(得分:0)

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