当前位置: 技术问答>java相关
JDBC连接ORACLE的异常,大侠救我!
来源: 互联网 发布时间:2017-03-20
本文导语: import java.io.*; import java.sql.*; class db { public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(Exception e) { System.out.println("出现异常:"+e....
import java.io.*;
import java.sql.*;
class db
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e)
{
System.out.println("出现异常:"+e.getMessage());
}
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con=
DriverManager.getConnection("jdbc:oracle:thin:@198.57.248.11:1521:ora816",
"hzxmz","abcde");
/*
如果通过ODBC连接,则是成功的:
Connection con=
DriverManager.getConnection("jdbc:odbc:diqing",
"hzxmz","bill");
*/
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select area_id,name from area");
while (rs.next())
System.out.println("AREAID:"+rs.getInt(1)+"t"+
"AREANAME:"+rs.getString(2)+"n");
stmt.close();
con.close();
}
catch (SQLException e)
{
System.out.println("检测到异常:"+e.getMessage());
}
}
}
//==============================================================
我用上述程序连接oracle数据库,出现异常
检测到异常:Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=135291648)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
问题出在哪里?
以上的数据库ip,sid,port都是可用的,用odbc,pb都可以正常连接
import java.sql.*;
class db
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(Exception e)
{
System.out.println("出现异常:"+e.getMessage());
}
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con=
DriverManager.getConnection("jdbc:oracle:thin:@198.57.248.11:1521:ora816",
"hzxmz","abcde");
/*
如果通过ODBC连接,则是成功的:
Connection con=
DriverManager.getConnection("jdbc:odbc:diqing",
"hzxmz","bill");
*/
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select area_id,name from area");
while (rs.next())
System.out.println("AREAID:"+rs.getInt(1)+"t"+
"AREANAME:"+rs.getString(2)+"n");
stmt.close();
con.close();
}
catch (SQLException e)
{
System.out.println("检测到异常:"+e.getMessage());
}
}
}
//==============================================================
我用上述程序连接oracle数据库,出现异常
检测到异常:Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=135291648)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
问题出在哪里?
以上的数据库ip,sid,port都是可用的,用odbc,pb都可以正常连接
|
将取出来的字符串用一下方法把编码转换就可以了
XXXX = new String(XXXXXX.getBytes("ISO8859_1"),"GB2312");
XXXX = new String(XXXXXX.getBytes("ISO8859_1"),"GB2312");