Java Io 异常:连接被拒绝(DESCRIPTION=(TMP=)(VSNNUM=168821248)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))) 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6503144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=168821248)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))) error
提问by Adnan
Yesterday i was using oracle 9.1 with ojdbc 14 jdbc driver with following code for adding employee, it was working fine but now i am using oracle 10.1.0.2.0 with ojdbc14 but now it is giving following error
昨天我使用 oracle 9.1 和 ojdbc 14 jdbc 驱动程序和以下代码添加员工,它工作正常,但现在我使用 oracle 10.1.0.2.0 和 ojdbc14 但现在它给出以下错误
Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=168821248)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))) error
Following is code for adding employee
以下是添加员工的代码
public static Connection getConnection() throws Exception {
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:5500:globldb3";
String username = "scott";
String password = "tiger";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}
public String addEmployee(){
Connection conn = null;
PreparedStatement pstmt = null;
boolean committed = false;
try {
conn = getConnection();
conn.setAutoCommit(false);
String query = "INSERT INTO
employee(e_id,e_name,e_f_name,e_desg,e_address,e_phone_no,"+
"e_salary,e_house_rent,e_conv_allow,e_email,d_name,e_hire_month,e_hire_year)"+
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(query);
pstmt = conn.prepareStatement(query); // create a statement
pstmt.setInt(1,this.eid);
pstmt.setString(2,this.ename);
pstmt.setString(3,this.efname);
pstmt.setString(4,this.edesg);
pstmt.setString(5,this.eaddress);
pstmt.setLong(6,this.ephoneno);
pstmt.setInt(7,this.esalary);
pstmt.setInt(8,this.houserent);
pstmt.setInt(9,this.convallow);
pstmt.setString(10,this.eemail);
pstmt.setString(11,this.edname);
pstmt.setInt(12,this.ehmon);
pstmt.setInt(13,this.ehy);
pstmt.executeUpdate(); // execute insert statement
conn.commit();
conn.setAutoCommit(true);
committed = true;
return "add-employee-msg.xhtml";
} catch (Exception e) {
e.printStackTrace();
return "add-employee-ex.xhtml";
} finally {
try{
if (!committed) conn.rollback();
if (pstmt != null) pstmt.close();
if (conn != null) conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
} //addEmployee
Any idea please?
请问有什么想法吗?
回答by Andreas Dolk
That's a configuration issue:
那是配置问题:
12505, 00000, "TNS:listener does not currently know of SID given in connect descriptor"
12505, 00000, "TNS:listener 当前不知道连接描述符中给出的 SID"
Maybe you just have to copy the original LISTENER.ORA
(correct name??) to your new oracle instance. You use the sid globldb3
which may be undefined on the 10.x instance.
也许您只需要将原始LISTENER.ORA
(正确的名称??)复制到您的新 oracle 实例。您使用在globldb3
10.x 实例上可能未定义的 sid 。
回答by user1697575
You have wrong DB URL.
你有错误的数据库 URL。
You have: "jdbc:oracle:thin:@localhost:5500:globldb3"
你有: "jdbc:oracle:thin:@localhost:5500:globldb3"
But should be: "jdbc:oracle:thin:@localhost:5500/globldb3"
<- notice slash instead of colon for the SID name.
但应该是:"jdbc:oracle:thin:@localhost:5500/globldb3"
<- 注意 SID 名称的斜线而不是冒号。
回答by madhav
Due to wrong SID/Servicename this issue will arise. Based on Servicename/SID, need to correct DB URL, otherwise it will be showing Connection refused error.
由于错误的 SID/Servicename 会出现此问题。基于Servicename/SID,需要更正DB URL,否则会显示Connection denied 错误。
format for both forms: JDBC URL FORMAT: jdbc:oracle:thin:@//:/ServiceName or jdbc:oracle:thin:@::
两种形式的格式:JDBC URL 格式:jdbc:oracle:thin:@//:/ServiceName 或 jdbc:oracle:thin:@::
回答by Subhasish
This should work :
这应该工作:
<property name="connection.url">jdbc:oracle:thin:@//localhost:1521/ORCL</property>
回答by Smartree
JDBC URL FOR ORACLE, wrong or correct, how do you know?
JDBC URL FOR ORACLE,错误还是正确,你怎么知道的?
INSTANCE SID by ":"
jdbc:oracle:thin:@db_ip_or_name:1521:ODB_IS
SERVICE NAME by "/"
jdbc:oracle:thin:@db_ip_or_name:1521/ODB_SN
How do you know?
SELECT NAME,VALUE,DESCRIPTION
FROM V$PARAMETER P
WHERE P.NAME IN ('db_unique_name','db_name','instance_name','service_names');*maybe you need your dba's help to query data dictionary view *----NAME-----|--VALUE--|--DESCRIPTION------------------------------ instance_name | ODB_IS | instance name supported by the instance service_names | ODB_SN | service names supported by the instance db_name | ODB_NM | database name specified in CREATE DATABASE db_unique_name| ODB_UN | Database Unique Name
The defferents are for RAC, DG; PRD,UAT,DEV deployment requirement etc.
Use service_names = db_name as normal, they must been see in 'lsnrctl status'PORT:
lsnrctl status
*run on the DB server shell window
实例 SID 由 ":"
jdbc:oracle:thin:@db_ip_or_name:1521:ODB_IS
“/”的服务名称
jdbc:oracle:thin:@db_ip_or_name:1521/ODB_SN
你怎么知道的?
SELECT NAME,VALUE,DESCRIPTION
FROM V$PARAMETER P
WHERE P.NAME IN ('db_unique_name','db_name','instance_name','service_names');*maybe you need your dba's help to query data dictionary view *----NAME-----|--VALUE--|--DESCRIPTION------------------------------ instance_name | ODB_IS | instance name supported by the instance service_names | ODB_SN | service names supported by the instance db_name | ODB_NM | database name specified in CREATE DATABASE db_unique_name| ODB_UN | Database Unique Name
不同的是 RAC、DG;PRD、UAT、DEV 部署要求等。
正常使用 service_names = db_name,它们必须在 'lsnrctl status' 中看到港口:
lsnrctl status
*在数据库服务器shell窗口上运行