NutzCN Logo
问答 Nutz连接Sqlserver报错
发布于 2919天前 作者 qq_665d1c15 4095 次浏览 复制 上一个帖子 下一个帖子
标签: dao sqlserver

db.properties

//由于工作原因我把真实服务器给隐藏了
db.url="jdbc:sqlserver://1.1.1.1:1433;databaseName=test"
db.username=******
db.password=******
db.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
db.validationQuery=select 1
db.maxActive=100

dao.js

var ioc = {
        conf : {
            type : "org.nutz.ioc.impl.PropertiesProxy",
            fields : {
                paths : ["custom/"]
            }
        },
        dataSource : {
            type : "com.alibaba.druid.pool.DruidDataSource",
            events : {
                create : "init",
                depose : 'close'
            },
            fields : {
                url : {java:"$conf.get('db.url')"},
                username : {java:"$conf.get('db.username')"},
                password : {java:"$conf.get('db.password')"},
                driverClassName : {java:"$conf.get('db.driverClassName')"},
                testWhileIdle : true,
                validationQuery : {java:"$conf.get('db.validationQuery')"},
                maxActive : {java:"$conf.get('db.maxActive')"},
                //druid监控
                filters : "mergeStat",
                connectionProperties : "druid.stat.slowSqlMillis=2000"
            }
        },
        dao : {
            type : "org.nutz.dao.impl.NutDao",
            args : [{refer:"dataSource"}]
        }
};

报错提示

java.sql.SQLException: connect error, url "jdbc:sqlserver://1.1.1.1;databaseName=test", driverClass com.microsoft.sqlserver.jdbc.SQLServerDriver
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1481)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1998)
23 回复

贴完整报错信息

就是完整报错提示的。其他的错误没有了

之前的日志

2016-12-29 16:20:09,978 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'dataSource'<>
2016-12-29 16:20:09,986 org.nutz.dao.impl.NutDao.<init>(NutDao.java:108) DEBUG - NutDao[_selfId=0] init ...
2016-12-29 16:20:10,002 org.nutz.filepool.NutFilePool.<init>(NutFilePool.java:23) INFO  - Init file-pool by: C:\Users\dzxla/.nutz/tmp/dao/ [200000]
2016-12-29 16:20:10,003 org.nutz.filepool.NutFilePool.<init>(NutFilePool.java:37) DEBUG - file-pool.home: 'C:\Users\dzxla\.nutz\tmp\dao'
2016-12-29 16:20:10,004 org.nutz.filepool.NutFilePool.<init>(NutFilePool.java:66) INFO  - file-pool.cursor: 0
2016-12-29 16:20:10,012 org.nutz.dao.jdbc.Jdbcs.<clinit>(Jdbcs.java:89) DEBUG - Jdbcs init complete
2016-12-29 16:20:10,012 org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:102) INFO  - Get Connection from DataSource for JdbcExpert, if you look at here, check your database server and configure
2016-12-29 16:20:10,032 com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2001) ERROR - create connection error, url: "jdbc:sqlserver://183.129.161.153:1433;databaseName=Gwms_bcw", errorCode 0, state null
java.sql.SQLException: connect error, url "jdbc:sqlserver://183.129.161.153:1433;databaseName=Gwms_bcw", driverClass com.microsoft.sqlserver.jdbc.SQLServerDriver
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1481)

把这一行去掉试试

validationQuery : {java:"$conf.get('db.validationQuery')"},

还是不行,不能用druid数据源绑定吗?出错的地方就是druid中得到连接总是为空的,但是该有的数据库信息都是有的

你的服务器的防火墙没关/放行1433端口? 或者只监听的127.0.0.1, 所以无法连接

刚检查了,上面的都是没问题的。防火墙一直就没开,监听,1433端口也是放开的,在sqlserver服务器上是可以连接的,但是还是连接不上。搞不懂什么原因了。。。。。

本地telnet一下就知道了

如果防火墙没开, 服务器上能连,外网不能连, 那肯定是监听127.0.0.1了

我把url换成jdbc可以连接的外网地址,还是连不上。

选的地址是可以正常连接访问的。

加一个 maxWait: 5000

这样抛错的信息应该完整些, 感觉你贴的报错信息缺了好多.

如果还是不行, 写段JDBC测试一下吧

我也纳闷,它就给我抛出日志记录这么一点信息,如果多点我都好找一点

完整信息如下

org.nutz.mvc.LoadingException: org.nutz.ioc.IocException: [dao] # FAIL to create Ioc Bean name=[dao]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:990)
	at org.nutz.lang.Lang.wrapThrow(Lang.java:196)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:135)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4563)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5205)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1404)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1394)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: org.nutz.ioc.IocException: [dao] # FAIL to create Ioc Bean name=[dao]
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:146)
	at com.bcw.kpi.MainSetup.init(MainSetup.java:36)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:277)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:121)
	... 15 more
Caused by: org.nutz.lang.born.BorningException: Fail to born 'org.nutz.dao.impl.NutDao'
 by args: [
  @({
	CreateTime:"2016-12-29 17:18:04",
	ActiveCount:0,
	PoolingCount:0,
	CreateCount:31,
	DestroyCount:0,
	CloseCount:0,
	ConnectCount:2,
	Connections:[
	]
})] because:
com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 5000, active 0, maxActive 8
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:19)
	at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
	... 21 more
Caused by: com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 5000, active 0, maxActive 8
	at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1190)
	at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1014)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544)
	at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:662)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:992)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:984)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:103)
	at org.nutz.trans.Trans.getConnectionAuto(Trans.java:263)
	at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:105)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:187)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:178)
	at org.nutz.dao.impl.NutDao.<init>(NutDao.java:113)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	... 23 more
Caused by: java.sql.SQLException: connect error, url "jdbc:sqlserver://115.231.97.119:1433;databaseName=Gwms_bcw", driverClass com.microsoft.sqlserver.jdbc.SQLServerDriver
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1481)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1998)

好吧,看不出来,只能上JDBC测试了

ConnectionID:1 ClientConnectionId: 0f60054e-f24e-4601-8936-ac59dc79faf2 JDBC连接成功的。。。

密码里面什么特殊字符之类的??

password : {java:"$conf.get('db.password')"},
// 改成
password : "直接写密码",

没有,可以识别的。

我只好用mysql了。mysql就是正常的。

额,好诡异

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