spring 连接oracle数据库报错{dataSource-1} init error解决,电脑用户名问题

错误描述:
连接oracle数据就报错,同样的代码其他电脑不会报错。

报错如下:
{dataSource-1} init error
java.sql.SQLRecoverableException: IO 错误: Undefined Error

com.alibaba.druid.pool.DruidDataSource-1049[main]ERROR: {dataSource-1} init error
java.sql.SQLRecoverableException: IO 错误: Undefined Error
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:774)
	at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:688)
	at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:39)
	at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:691)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1657)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1723)
	at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:927)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1401)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1397)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:100)
	at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:151)
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:600)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:657)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:688)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:700)
	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:771)
	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:792)
	at com.ynyc.service.DbService.checkTable(DbService.java:116)
	at com.ynyc.App.main(App.java:52)
Caused by: oracle.net.ns.NetException: Undefined Error
	at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:271)
	at oracle.net.ns.NSProtocol.connect(NSProtocol.java:317)
	at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1438)
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:518)
	... 20 more

原因是电脑用户名是中文的。

解决:
在连接之前加入该行代码:

//Java代码:
//解决电脑名为中文,不能连接数据库问题
System.setProperty("user.name", "yingwen");
//.bat代码:
@echo off
set USER_NAME=yingwen


//.sh代码:
#!/bin/bash
export USER_NAME=yingwen

其他:
修改电脑用户名,太麻烦,放弃了。

你可能感兴趣的:(数据库,数据库,spring,oracle)