com.ibm.db2.jcc.b.DisconnectException: A communication error has been detected. Communication protoc

com.ibm.db2.jcc.b.DisconnectException: A communication error has been detected. Communication protocol being used: Reply.fill().
Communication API being used: InputStream.read(). Location where the error was detected: insufficient data.
Communication function detecting the error: *. Protocol specific error codes(s) TCP/IP SOCKETS   DB2ConnectionCorrelator: null

本人遇到的问题的原因是:两个数据库oracle和db2公用了一个端口50000

我在window7上连续装了两个数据库,安装的时候是默认端口,没注意两个端口都是50000

后来修改C:\Windows\System32\drivers\etc下面的文件services

com.ibm.db2.jcc.b.DisconnectException: A communication error has been detected. Communication protoc_第1张图片

重新关闭数据库,然后再打开

 

最后用下面代码测试数据库连接

try{

    Date strat=new Date();

   Class.forName("com.ibm.db2.jcc.DB2Driver");//加载驱动

   String url = "jdbc:db2://localhost:50001/TGR_DB";//

   Connection con = DriverManager.getConnection(url,"db2admin","Admin1234");

   con.close();

   Date end=new Date();

   System.out.println("连接成功,用时:"+(end.getTime()-strat.getTime())); 

  }catch(Exception se){

   se.printStackTrace();

  }  

你可能感兴趣的:(java,数据库,jdbc,db2)