我正在尝试使用JAVA连接到远程Oracle BD。首先,我用这种方式连接OracleDataSource:
OracleDataSource fdo = new OracleDataSource();
fdo.setDatabaseName("orc1");
fdo.setDriverType("thin");
fdo.setServerName("150....");
fdo.setPortNumber(1521);
con = fdo.getConnection("...", "...");
连接正常。
但是现在,我刚接触到Oracle驱动程序。 我这样做了:
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con =DriverManager.getConnection("jdbc:oracle:thin:@150....:1521/orc1","....","....");
Statement s = con.createStatement();
ResultSet result = s.executeQuery("select *from MRALOGIN");
while(result.next()){
System.out.println(result.getString(1));
}
但这产生了下一个例外:
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in
connect descriptor
有人知道为什么吗?服务orc1存在,主机方向有效......我使用OracleDataSource
连接进行了测试。