NutzCN Logo
问答 nutzboot多数据源配置oracle出错
发布于 2091天前 作者 lrw124 3185 次浏览 复制 上一个帖子 下一个帖子
标签:

1、pom.xml中使用

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>12.1.0.1-atlassian-hosted</version>
    <!-- <scope>test</scope> -->
</dependency>

2、db.properties中已默认mysql配置,再配置oracle

jdbc.many.myoracle.type=druid
jdbc.many.myoracle.url=jdbc:oracle:thin:@38.43.64.103:1521:orcl:myoracle
...

3、日志中报错信息

2019-04-01 22:24:46  [ Druid-ConnectionPool-Create-644345897:1807 ] - [ ERROR ]  create connection SQLException, url: jdbc:oracle:thin:@38.43.64.103:1521:orcl:myoracle, errorCode 17002, state 08006
java.sql.SQLRecoverableException: IO 错误: Invalid connection string format, a valid format is: "host:port:sid" 
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673)
	at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:711)
	at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
	at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
	at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:558)
	at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:156)
	at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218)
	at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1572)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1636)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2505)
Caused by: oracle.net.ns.NetException: Invalid connection string format, a valid format is: "host:port:sid" 
	at oracle.net.resolver.AddrResolution.resolveSimple(AddrResolution.java:535)
	at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:441)
	at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:594)
	at oracle.net.ns.NSProtocol.connect(NSProtocol.java:229)
	at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
	... 10 more
12 回复
jdbc.many.myoracle.url=jdbc:oracle:thin:@38.43.64.103:1521:orcl:myoracle

最后面的:myoracle是写多了?

难道是我借鉴错了?还是没有处理含Oracle在内的多数据源?

# 注意:目前多数据注入,只支持type为druid的方式,所以以下所有db都配置type为druid
# 默认数据库 注入对象 dao
jdbc.type=druid
jdbc.url=jdbc:h2:mem:~
# news数据库 注入对象 newsDao
jdbc.many.news.type=druid
jdbc.many.news.url=jdbc:h2:mem:news

oracle的jdbc url 是怎样写的, 就怎么写, 跟h2database的jdbcurl没一点关系

1、配置

jdbc.many.orcl.type=druid
jdbc.many.orcl.url=jdbc:oracle:thin:@38.43.64.103:1521:orcl

2、注入

@Inject
	protected Dao orclDao;

3、日志

java.lang.NullPointerException

日志就一行?

java.lang.NullPointerException
        at net.xwyun.pirs4j.core.Backend.parseRequest(Backend.java:452)
        at net.xwyun.pirs4j.module.MyServer$Handler.run(MyServer.java:134)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:624)
        at java.lang.Thread.run(Thread.java:748)

451行的代码是

Accinfo accinfo = orclDao.fetch(Accinfo.class, cnd);

在前一行写了一句

log.debug(orclDao);

输出 null

nutzboot已使用 2.3.4-SNAPSHOT

更正,452行是

Accinfo accinfo = orclDao.fetch(Accinfo.class, cnd);

声明orclDao属性的那个类, 没加@IocBean, 或者对象是直接new的

@IocBean
public class Backend {
	@Inject
	protected Dao dao;
	@Inject
	protected Dao orclDao;

配置中many.后面的名称,只是一个自定义的标识名吗?还是有什么定义规则?


jdbc.many.orcl.type=druid jdbc.many.orcl.url=jdbc:oracle:thin:@38.43.64.103:1521:orcl

只是一个标识,一般变量名的规则

那目测Backend 是直接new出来的? 所以没注入?

Backend没有直接new出来,但其继承类的实例是new出来的。谢谢!@wendal

添加回复
请先登陆
回到顶部