我试图运行下面的代码被连接到远程数据库和检索记录Oracle数据库:连接到位于远程
import java.sql.*;
class Employee
{
public static void main (String args [])
throws SQLException, ClassNotFoundException {
// Load the Oracle JDBC driver
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as <host>:<port>:<sid>. The example uses the short cut syntax.
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@ourcompany.com:1521:course", "username", "password");
// Create a Statement
Statement stmt = conn.createStatement();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select * from test");
// Iterate through the result and print the employee names
/*
while (rset.next())
System.out.println (rset.getString ("name"));
System.out.println (rset.getString ("id"));
*/
rset.next();
System.out.println(rset.getString("name"));
} }
从NetBeans中运行此代码我得到一个后错误:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@ourcompany.com:1521:course at java.sql.DriverManager.getConnection(DriverManager.java:604) at java.sql.DriverManager.getConnection(DriverManager.java:221) at Employee.main(Emplyoee.java:23) Java Result: 1 BUILD SUCCESSFUL (total time: 2 seconds)
我已经下载ojdbc14.jar的,并保存在C:\ Program Files文件\的Java \ jdk1.7.0 \ JRE \ lib文件路径。 我不知道我哪里去错了... ... plz帮助我在这里。
我试过这个...得到了同样的错误。 – kpc72 2011-12-14 22:44:13
你确定jar文件在你的类路径中吗? – chance 2011-12-14 22:45:34