Java到Oracle的连接问题

时间:2014-12-15 12:01:58

标签: java oracle

我使用以下代码连接oracle 10g并检索一些数据。

public static void main(String[] args) {
    try{  
        Class.forName("oracle.jdbc.driver.OracleDriver");  
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521/orcl","scott","tiger");  
        Statement stmt=con.createStatement();  
        ResultSet rs=stmt.executeQuery("select * from emp");  
        while(rs.next())  
        System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));  
        con.close();  

    }
    catch(Exception e)
    { 
        System.out.println(e);
    }     
}

它可以正常运行一段时间,但有时它会抛出错误并且没有连接:

java.sql.SQLException: Listener refused the connection with the following error:

ORA-12518, TNS:listener could not hand off client connection

The Connection descriptor used by the client was:

127.0.0.1:1521/orcl

2 个答案:

答案 0 :(得分:0)

尝试设置

  

DIRECT_HANDOFF_TTC_LISTENER = OFF

你会发现这个文件是$ oraclehome / product / $ version / server / listners.ora

有时,由于资源有限,也可能会发生这种情况。在你做任何事情之前尝试重新启动oracle,在这样做之后,如果问题消失,那就意味着资源有限。

答案 1 :(得分:0)

鉴于间歇性行为,您可能会遇到服务器问题或达到限制。检查listener.log和alert.log以查看是否存在阻止创建会话的另一个基础Oracle错误。

我的猜测是你有太多的会话或过程。计算v $ session和v $ process视图中的行数,并与数据库参数“sessions”和“processes”进行比较。你可能不得不增加它们。另外,检查你的应用程序是否没有留下未使用的会话,否则无论你设置参数多高,你都会用完会话。