java - Io异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=168821248)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))) error

标签 java jdbc jakarta-ee

昨天我使用带有 ojdbc 14 jdbc 驱动程序的 oracle 9.1,并使用以下代码添加员工,它工作正常,但现在我使用带有 ojdbc14 的 oracle 10.1.0.2.0,但现在它给出以下错误

Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=168821248)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))) error

以下是添加员工的代码

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

请问有什么想法吗?

最佳答案

这是一个配置问题:

12505, 00000, "TNS:listener does not currently know of SID given in connect descriptor"

也许您只需将原始的LISTENER.ORA(正确的名称??)复制到新的oracle实例。您使用的 sid globldb3 在 10.x 实例上可能未定义。

关于java - Io异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=168821248)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4)))) error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6503144/

相关文章:

java - 创建行程成本计算器

java - Struts2 REST 插件 : Sending JSON object through PUT

java - 程序在Java中抛出java.lang.UnsupportedOperationException

java - 为什么我必须在 JDBC 中使用回滚?

java - 如何从 JNDI 加载 log4j2 配置文件

java - 使用执行器创建消息监听器池

jakarta-ee - 如何防止用户在网站上多次发布数据

java - JSF2 : ui:include: Component ID must be unique

java - 在 Java Standard Edition 中运行 Java Mobile 应用程序

java - 无法为连接 URL '' 创建类 'null' 的 JDBC 驱动程序 - :ERROR while creating and using a Datasource in tomcat 6