当前位置: 代码迷 >> Java相关 >> ORA-12518, TNS:listener could not hand off client connection
  详细解决方案

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

热度:7277   发布时间:2013-02-25 21:52:09.0
oracle的连接问题,求各位大大帮忙解决
package orcal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class aa {

public static void main(String args[]){
ResultSet rs = null;
Statement stmt = null;
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
//类装载器 根据字符串的名字把类的实例new出来,自动向DriverManger注册

conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:oracle1", "scott", "tiger"); //1521为默认 拿到oracle数据库的连接
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from table1");
while(rs.next()) { //拿出表中的记录
System.out.println(rs.getString("name"));
System.out.println(rs.getString("age"));
}
}catch (ClassNotFoundException ee) {
ee.printStackTrace();
}catch (SQLException e) {
e.printStackTrace();
}finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt = null;
}
if(conn != null) {
conn.close();
conn = null;
}
//后打开先关闭
}catch (SQLException e) {
e.printStackTrace();
}
}

}
}

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:
localhost:1522:oracle1

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:439)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at orcal.aa.main(aa.java:17)


------解决方案--------------------------------------------------------
探讨
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:
localhost:1522:oracle1

------解决方案--------------------------------------------------------
网络不通/Oracle配置不对

楼主检查一下

祝你好运
------解决方案--------------------------------------------------------
检查一下查询语句查询出来的*,是不是又第二列和第三列
------解决方案--------------------------------------------------------
如果table3表中没有数据,则不会有输出。
------解决方案--------------------------------------------------------
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:abc"-(1), "scott"-(2), "aaa"-(3));
(1)为连接的URL 其中1522是Oracle的连接端口号,一般为1521 后面有"abc"这个是Oracle的版本号,我不清楚楼主为什么要写一个“abc”,但就目前而言是没有"abc"这个版本号的 
(2)是你数据库的用户名
(3)是数据库的密码
一般是这样写的
conn =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","username","userpwd");
你去试试,我想应该是版本号和端口的问题吧!
  相关解决方案