当前位置: 代码迷 >> Java Web开发 >> oracle连接有关问题
  详细解决方案

oracle连接有关问题

热度:87   发布时间:2016-04-17 01:28:08.0
oracle连接问题
package com.cityinfo.dbconnection;

import java.sql.*;
import java.util.Properties;

public class DBConnection {
public static Connection getCon(){
Connection conn = null;
String url = "jdbc:oracle:thin:@localhost:1521:DB_CITYINFO_DATA";
String user="zhouxin"; 
String pw="zhouxin"; 
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection(url,user,pw);
}catch(Exception ex){
ex.printStackTrace();
}
return conn;
}

public static void main(String[] args){
System.out.println(DBConnection.getCon());
}
}

java.sql.SQLException: Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:404)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:468)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.cityinfo.dbconnection.DBConnection.getCon(DBConnection.java:14)
at com.cityinfo.dbconnection.DBConnection.main(DBConnection.java:22)
null

------解决方案--------------------
或许是oracle没有正常启动,还有可能也就是oracle的网络连接没有打开,或则是oracle的默认网络连接端口1521被你改过,你可以试着找下这些问题,代码看不出来有问题!
------解决方案--------------------
[color=#FF0000][/color]java code

import java.sql.Connection;
import java.sql.DriverManager;

public class DBConnection {
public static Connection getCon() {
Connection conn = null;
String url = "jdbc:oracle:thin:@localhost:1521:wgb";
String user = "scott";
String pw = "tiger";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, user, pw);
} catch (Exception ex) {
ex.printStackTrace();
}
return conn;
}

public static void main(String[] args) {
System.out.println(DBConnection.getCon());
}
}

结果:oracle.jdbc.driver.OracleConnection@131f71a
基本没有改动你的代码,可以肯定你的问题在于,1、oracle服务没有开启;2、没有将oracle的驱动包,class12.jar加入到lib中,就这两种情况自己检查吧
  相关解决方案