JavaJDBC-如何使用服务名称而不是SID连接到Oracle我有一个使用JDBC(通过JPA)的Java应用程序,它使用主机名、端口和Oracle SID连接到开发数据库,如下所示:jdbc:oracle:thin:@oracle.hostserver1.mydomain.ca:1521:XYZXYZ是Oracle SID。现在,我需要连接到一个不同的Oracle数据库,它不使用SID,而是使用Oracle的“服务名称”。我试过了,但没用:jdbc:oracle:thin:@oracle.hostserver2.mydomain.ca:1522:ABCDABCD是另一个数据库的服务名称。我做错什么了?
3 回答
紫衣仙女
TA贡献1839条经验 获得超15个赞
jdbc:oracle:thin:@//HOSTNAME:PORT/SERVICENAME
jdbc:oracle:thin:@(description=(address=(host=HOSTNAME)(protocol=tcp)(port=PORT))(connect_data=(service_name=SERVICENAME)(server=SHARED)))
青春有我
TA贡献1784条经验 获得超8个赞
import java.sql.*; public class MyDBConnect { public static void main(String[] args) throws SQLException { try { String dbURL = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=whatEverYourHostNameIs)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=yourServiceName)))"; String strUserID = "yourUserId"; String strPassword = "yourPassword"; Connection myConnection=DriverManager.getConnection(dbURL,strUserID,strPassword); Statement sqlStatement = myConnection.createStatement(); String readRecordSQL = "select * from sa_work_order where WORK_ORDER_NO = '1503090' "; ResultSet myResultSet = sqlStatement.executeQuery(readRecordSQL); while (myResultSet.next()) { System.out.println("Record values: " + myResultSet.getString("WORK_ORDER_NO")); } myResultSet.close(); myConnection.close(); } catch (Exception e) { System.out.println(e); } }}
添加回答
举报
0/150
提交
取消