[英]JDBC connection from eclipse not working, but working in Oracle SQL developer
我正在尝试通过JDBC连接到数据库
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@host_name:port:service_name"; //Changed the host_name, port and service_name for confidentiality
String username = "user_name"; // Changed the user_name
String password = "my_password"; //Changed the password
Connection conn = DriverManager.getConnection(url, username, password);
得到了以下异常
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
但是同时,我可以通过Oracle SQL开发人员进行连接。
注意:我的service_name由“。”组成。 和“ _”,而我的host_name包含“。”
请在这里帮助!
//Step: 1
Load Driver Class
ex- Class.forName("oracle.jdbc.driver.OracleDriver");
//Step: 2
String url="jdbc:oracle:thin:@ipaddress:portNo of oracle :database name";
ex- String url="jdbc:oracle:thin:@localhost:1521:XE";
//Step: 3
User Name
String username = "user_name";
ex- String username = "system";
//Step: 3
Password
String password = "oracle_db_Password";
ex- String password = "sys123";
//Step:4
Connection con=DriverManager.getConnection(url,username,password);
以下是从oracle文档创建数据源对象的正确方法:
//指定数据源对象
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:@//myhost:1521/orcl");
ods.setUser("scott");
ods.setPassword("tiger");
Connection conn = ods.getConnection();
希望您使用正确
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.