我想把问题描述得更加具体一些:
我以前用的是Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production
现在是Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
现在用的classes12.jar还是前者里面自带的,(问题是不是出在这?)
我这有一个测试程序
import java.sql.*;class Dbtest {
public static void main(String[] args) throws Exception{
Connection conn=null;
String strDBDriver="oracle.jdbc.OracleDriver";
String DBURL="jdbc:oracle:thin:@10.119.16.10:1521:op1.domain";
String strDBUser="power";
String strUserPassword="power";
try{
Class.forName(strDBDriver).newInstance();
conn = DriverManager.getConnection(DBURL,strDBUser,strUserPassword);
}catch(java.lang.ClassNotFoundException e1){
System.err.println("e1:"+e1.getMessage());
}catch(java.lang.InstantiationException e2){
System.err.println("e2:"+e2.getMessage());
}catch(java.lang.IllegalAccessException e3){
System.err.println("e3:"+e3.getMessage());
}catch(SQLException e4){
System.err.println("e4:"+e4.getMessage());
}
ResultSet rs=null;
Statement stmt;
for(int l=0;l<5;l++){
stmt = conn.createStatement();
String sql="select '1'||'2' from dual";
try{
rs = stmt.executeQuery(sql);
}catch(SQLException e){
System.err.println("executeQuery():"+e.getMessage());
rs = null;
}
if(rs==null){
System.err.println("rs is null");
System.exit(1);
}else{
System.out.println("-----------");
try{
int i=1;
while(rs.next()){
String s1=rs.getString(1);
System.out.println((l)+": "+s1);
}
}catch(Exception e){
System.err.println("error");
e.printStackTrace();
}
}
stmt.close();
stmt=null;
}
}
}出现的错误是:
---------- 运行 ----------
e4:Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
java.lang.NullPointerException
at Dbtest.main(Dbtest.java:37)
Exception in thread "main" Normal Termination
Output completed (0 sec consumed).我现在客户现场作实施,时间紧迫,希望各位大侠仗义相助.
我以前用的是Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production
现在是Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
现在用的classes12.jar还是前者里面自带的,(问题是不是出在这?)
我这有一个测试程序
import java.sql.*;class Dbtest {
public static void main(String[] args) throws Exception{
Connection conn=null;
String strDBDriver="oracle.jdbc.OracleDriver";
String DBURL="jdbc:oracle:thin:@10.119.16.10:1521:op1.domain";
String strDBUser="power";
String strUserPassword="power";
try{
Class.forName(strDBDriver).newInstance();
conn = DriverManager.getConnection(DBURL,strDBUser,strUserPassword);
}catch(java.lang.ClassNotFoundException e1){
System.err.println("e1:"+e1.getMessage());
}catch(java.lang.InstantiationException e2){
System.err.println("e2:"+e2.getMessage());
}catch(java.lang.IllegalAccessException e3){
System.err.println("e3:"+e3.getMessage());
}catch(SQLException e4){
System.err.println("e4:"+e4.getMessage());
}
ResultSet rs=null;
Statement stmt;
for(int l=0;l<5;l++){
stmt = conn.createStatement();
String sql="select '1'||'2' from dual";
try{
rs = stmt.executeQuery(sql);
}catch(SQLException e){
System.err.println("executeQuery():"+e.getMessage());
rs = null;
}
if(rs==null){
System.err.println("rs is null");
System.exit(1);
}else{
System.out.println("-----------");
try{
int i=1;
while(rs.next()){
String s1=rs.getString(1);
System.out.println((l)+": "+s1);
}
}catch(Exception e){
System.err.println("error");
e.printStackTrace();
}
}
stmt.close();
stmt=null;
}
}
}出现的错误是:
---------- 运行 ----------
e4:Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=153092352)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))
java.lang.NullPointerException
at Dbtest.main(Dbtest.java:37)
Exception in thread "main" Normal Termination
Output completed (0 sec consumed).我现在客户现场作实施,时间紧迫,希望各位大侠仗义相助.
在oracle安装目录下的jdbc目录下有!
因为我连接的数据库是运行在双机上,做了负载均衡,而op1.domain不是一个全局数据库名,而是一个服务名。所以只能使用特定的连接串(和tnsnames.ora文件中匹配的连接串)来连接。jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.119.16.1)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=10.119.16.2)(PORT=1521))(LOAD_BALANCE=yes))(CONNECT_DATA=(SERVICE_NAME = op1.domain)))相信大家看到这个,因该明白是怎么回事了。大家以后碰到类似问题,可以如此解决。
最后谢谢各位热心人的帮助!