NutzCN Logo
问答 连接SQLSERVER时报错
发布于 2991天前 作者 qq_519c39e0 2312 次浏览 复制 上一个帖子 下一个帖子
标签:

今天遇到需要连接SQLSERVER的需求,不过改配置后发现出现异常。

先贴dao.js的代码
var ioc = {
conf : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : ["custom/db.properties"]
}
},
dataSource : {
type:"org.apache.commons.dbcp.BasicDataSource",
events : {
depose : 'close'
},
fields : {
driverClassName : {java:"$conf.get('db.driverClassName')"},
url : {java:"$conf.get('db.url')"},
username : {java:"$conf.get('db.username')"},
password : {java:"$conf.get('db.password')"},
testWhileIdle : true,
maxActive : {java:"$conf.get('db.maxActive')"}
}
},
dao : {
type : "org.nutz.dao.impl.NutDao",
args : [{refer:"dataSource"}]
}
};


然后是db.propertity的代码

db.url=jdbc:sqlserver://1.1.1.1\SQL2008,49217:1433;databaseName=HY_Demo
db.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
db.username=zl
db.password=zl
db.maxActive=200


以下是启动时的报错日志

严重: Exception starting filter nutz
org.nutz.mvc.LoadingException: org.nutz.ioc.IocException: Fail to born 'org.nutz.dao.impl.NutDao'
by args: [
@(org.apache.commons.dbcp.BasicDataSource@3125f499)] becasue:
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (用户 'zl' 登录失败。) FAIL to create Ioc Bean name=[dao]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
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:988)
at org.nutz.lang.Lang.wrapThrow(Lang.java:165)
at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:134)
at org.nutz.mvc.ActionHandler.(ActionHandler.java:19)
at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
at com.chiefdom.authority.filter.MainNutFilter.init(MainNutFilter.java:22)
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.(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

```

也确认过帐号和密码通过工具能正常连接

4 回复

没有贴完整

严重: Exception starting filter nutz
org.nutz.mvc.LoadingException: org.nutz.ioc.IocException: Fail to born 'org.nutz.dao.impl.NutDao'
 by args: [
  @(org.apache.commons.dbcp.BasicDataSource@3125f499)] becasue:
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (用户 'zl' 登录失败。) FAIL to create Ioc Bean name=[dao]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
	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:988)
	at org.nutz.lang.Lang.wrapThrow(Lang.java:165)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:134)
	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 com.chiefdom.authority.filter.MainNutFilter.init(MainNutFilter.java:22)
	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:4809)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.ioc.IocException: Fail to born 'org.nutz.dao.impl.NutDao'
 by args: [
  @(org.apache.commons.dbcp.BasicDataSource@3125f499)] becasue:
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (用户 'zl' 登录失败。) FAIL to create Ioc Bean name=[dao]
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:147)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:204)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:229)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:148)
	at com.chiefdom.MainSetup.init(MainSetup.java:20)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:276)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:120)
	... 16 more
Caused by: org.nutz.lang.born.BorningException: Fail to born 'org.nutz.dao.impl.NutDao'
 by args: [
  @(org.apache.commons.dbcp.BasicDataSource@3125f499)] becasue:
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (用户 'zl' 登录失败。)
	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)
	... 22 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (用户 'zl' 登录失败。)
	at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
	at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
	at org.nutz.trans.Trans.getConnectionAuto(Trans.java:263)
	at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:106)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:174)
	at org.nutz.dao.impl.NutDao.<init>(NutDao.java:112)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	... 24 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'zl' 登录失败。
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
	at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
	at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2529)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1905)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1893)
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1045)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
	at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
	at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
	at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
	at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
	at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
	... 35 more

妥妥的密码错误

@wendal 主要是一开始配置的链接写法有问题,然后对方端口号也不是用的1433,问题已经解决了。
最终的jdbc连接是jdbc:sqlserver://1.1.1.1:1433;databaseName=HY_Demo

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