【发布时间】:2012-01-20 16:39:36
【问题描述】:
我正在尝试运行以下连接远程数据库并检索记录的代码:
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 运行此代码后,我收到一个错误:
线程“main”java.sql.SQLException 中的异常:找不到适合 jdbc:oracle:thin:@ourcompany.com:1521:course 的驱动程序 在 java.sql.DriverManager.getConnection(DriverManager.java:604) 在 java.sql.DriverManager.getConnection(DriverManager.java:221) 在 Employee.main(Emplyoee.java:23) Java 结果:1 构建成功(总时间:2 秒)
我已经下载了 ojdbc14.jar 并保存在 C:\Program Files\Java\jdk1.7.0\jre\lib 路径中。 我不知道我哪里出错了?...请在这里帮助我。
【问题讨论】:
标签: oracle netbeans jdbc database-connection