我正在尝试通过Eclipse连接到我们的oracle数据库。我有以下包裹。
我们在Oracle 11g Java 1.7 我已经下载了ojdbc7.jar驱动程序并将其放在类路径中。
//connection code
package testConnect;
import java.sql.*;
import oracle.jdbc.OracleDriver;
public class JdbcThinTnsNamesTest {
public JdbcThinTnsNamesTest() {
System.setProperty("oracle.net.tns_admin",
"$TNS_ADMIN");
}
public static Connection getConnection() throws SQLException {
String username = "user";
String password = "password";
String thinConn = "jdbc:oracle:thin:@//NCPP";
DriverManager.registerDriver(new OracleDriver());
Connection conn = DriverManager.getConnection(thinConn, username,
password);
conn.setAutoCommit(false);
return conn;
}
//
public void run() throws SQLException {
Connection conn = getConnection();
System.out.println("Auto Commit = " + conn.getAutoCommit());
conn.close();
}
public static void main(String[] args) {
JdbcThinTnsNamesTest test = new JdbcThinTnsNamesTest();
try {
test.run();
System.out.println("all done..");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
//
但我一直收到以下错误:
java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@//NCPP at java.sql.DriverManager.getConnection(DriverManager.java:596) at java.sql.DriverManager.getConnection(DriverManager.java:215) at testConnect.JdbcThinTnsNamesTest.getConnection(JdbcThinTnsNamesTest.java:17) at testConnect.JdbcThinTnsNamesTest.run(JdbcThinTnsNamesTest.java:24) at testConnect.JdbcThinTnsNamesTest.main(JdbcThinTnsNamesTest.java:32)
不确定这是Eclipse问题,我的代码还是两者兼而有之。