出现问题:

我的代码是通过本机eclipse访问电脑虚拟机安装的oracle数据库数据,出现了Io 异常: The Network Adapter could not establish the connection,这个异常是由于ui端接口发送数据进行接口访问时出现的。

处理过程:

1.修改虚拟机oracle监听配置,配置listener和tnsnames文件,这两个文件在db_home2中,不是在db_home1中,一定要注意。

2.配置了监听的主机名,一定是主机名不然没法访问,具体如下图所示。

3.修改eclipse中的application.yml文件中的连接,改成了:  host:端口:SID,,在这里host是我的主机名(主机名通过计算机属性查看,后面一般带有-PC),端口是1521,注意是SID不是全局数据库名。

listener配置文件:

# listener.ora Network Configuration File: C:\app\st\product\11.2.0\dbhome_2\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = CLRExtProc)
      (ORACLE_HOME = C:\app\st\product\11.2.0\dbhome_2)
      (PROGRAM = extproc)
      (ENVS = "EXTPROC_DLLS=ONLY:C:\app\st\product\11.2.0\dbhome_2\bin\oraclr11.dll")
    )
  )

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = st-PC)(PORT = 1521))
  )

ADR_BASE_LISTENER = C:\app\st

tnsnames配置文件:

# tnsnames.ora Network Configuration File: C:\app\st\product\11.2.0\dbhome_2\NETWORK\ADMIN\tnsnames.ora
# Generated by Oracle configuration tools.

LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.80.3)(PORT = 1521))


ORACLR_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(Key = EXTPROC1521))
    )
    (CONNECT_DATA =
      (SID = CLRExtProc)
      (PRESENTATION = RO)
    )
  )

ORCL =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = st-PC)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl.168.153.154)
    )
  )

SQLNET配置文件:
SQLNET.AUTHENTICATION_SERVICES= (NTS)

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

监听配置:

application.yml文件配置:

注意:文件配置严格按照格式来,只能是用空格键,不能使用tab键。

spring:
  datasource:
    url : jdbc:oracle:thin:@st-PC:1521:ORCL
    username: SCOTT
    password: st
    driver-class-name: oracle.jdbc.OracleDriver

mybatis:
  mapperLocations :
    classpath:mapper/*Mapper.xml

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐