问题
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
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?
回答1:
That's a configuration issue:
12505, 00000, "TNS:listener does not currently know of SID given in connect descriptor"
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.
回答2:
You have wrong DB URL.
You have: "jdbc:oracle:thin:@localhost:5500:globldb3"
But should be: "jdbc:oracle:thin:@localhost:5500/globldb3"
<- notice slash instead of colon for the SID name.
回答3:
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.
format for both forms: JDBC URL FORMAT: jdbc:oracle:thin:@//:/ServiceName or jdbc:oracle:thin:@::
回答4:
This should work :
<property name="connection.url">jdbc:oracle:thin:@//localhost:1521/ORCL</property>
回答5:
JDBC URL FOR ORACLE, wrong or correct, how do you know?
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
来源:https://stackoverflow.com/questions/6503144/io-exception-connection-refuseddescription-tmp-vsnnum-168821248err-12505