NutzCN Logo
问答 项目启动有数据操作就报 create connection error,求解
发布于 3322天前 作者 numbgui 23623 次浏览 复制 上一个帖子 下一个帖子
标签: dao

这里是tomcat报错信息
(环境:nutz1.53,jdk7,tomcat7)

十一月 18, 2015 9:26:47 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory D:\apache-tomcat-7\webapps\ROOT has finished in 7,110 ms
十一月 18, 2015 9:26:47 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-apr-88"]
十一月 18, 2015 9:26:47 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-apr-8009"]
十一月 18, 2015 9:26:47 上午 org.apache.catalina.startup.Catalina start
信息: Server startup in 7285 ms
2015-11-18 09:28:33,570 [INFO][org.nutz.dao.jdbc.Jdbcs] - Get Connection from DataSource for JdbcExpert
2015-11-18 09:28:33,820 [INFO][com.alibaba.druid.pool.DruidDataSource] - {dataSource-2} inited
2015-11-18 09:28:34,210 [ERROR][com.alibaba.druid.pool.DruidDataSource] - create connection error
java.sql.SQLException: ResultSet is from UPDATE. No Data.
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
        at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:7158)
        at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3890)
        at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3431)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2386)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
        at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1375)
        at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1431)
        at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1844)
2015-11-18 09:28:34,257 [ERROR][com.alibaba.druid.pool.DruidDataSource] - create connection error
java.sql.SQLException: ResultSet is from UPDATE. No Data.
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
        at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:7158)
        at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3890)
        at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3431)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2386)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
        at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1375)
        at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1431)
        at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1844)

这里是datasource.json数据库配置文件

var ioc = {
	dataSource:{
		type:"com.alibaba.druid.pool.DruidDataSource",
		events:{
			depose:"close"
		},
		fields:{
			driverClassName:"com.microsoft.sqlserver.jdbc.SQLServerDriver",
			url:"jdbc:sqlserver://192.168.0.239:1433;databaseName=xxx",
			username:"sa",
			password:"pass",
			maxActive:20,
			testWhileIdle:true,
			validationQuery:'SELECT COUNT(*) FROM Banned_User_Table',
			removeAbandoned:true ,
			removeAbandonedTimeout:1800,
			filters : "mergeStat",
			connectionProperties : "druid.stat.slowSqlMillis=2000"
		}
	},
	dao: {
		type : "org.nutz.dao.impl.NutDao",
		args : [{refer:'dataSource'}]
	},
	dataSource2:{
		type:"com.alibaba.druid.pool.DruidDataSource",
		events:{
			depose:"close"
		},
		fields:{
			url:"jdbc:mysql://192.168.0.239:3306/xxxx?useUnicode=true",
			username:"root",
			password:"pass",
			maxActive:20,
			testWhileIdle:true,
			validationQuery:'SELECT COUNT(*) FROM SYS_DBTEST',
			removeAbandoned:true ,
			removeAbandonedTimeout:1800
		}
	},
	dao2 : {
		type : "org.nutz.dao.impl.NutDao",
		args : [{refer:'dataSource2'}]
	}
}
7 回复

报错信息。。。
信息: Server startup in 6592 ms
2015-11-18 09:36:35,747 [INFO][org.nutz.dao.jdbc.Jdbcs] - Get Connection from DataSource for JdbcExpert
2015-11-18 09:36:35,772 [INFO][com.alibaba.druid.pool.DruidDataSource] - {dataSource-2} inited
2015-11-18 09:36:36,351 [ERROR][com.alibaba.druid.pool.DruidDataSource] - create connection error
java.sql.SQLException: ResultSet is from UPDATE. No Data.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:7158)
at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3890)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3431)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2386)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:794)
at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1375)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1431)
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1844)

数据库配置文件:
var ioc = {
dataSource:{
    type:"com.alibaba.druid.pool.DruidDataSource",
    events:{
       depose:"close"
    },
    fields:{
       driverClassName:"com.microsoft.sqlserver.jdbc.SQLServerDriver",
       url:"jdbc:sqlserver://192.168.0.239:1433;databaseName=crossgate",
       username:"sa",
       password:"pass",
       maxActive:20,
       testWhileIdle:true,
       validationQuery:'SELECT COUNT(*) FROM Banned_User_Table',
       removeAbandoned:true ,
       removeAbandonedTimeout:1800,
       filters : "mergeStat",
       connectionProperties : "druid.stat.slowSqlMillis=2000"
    }
},
dao: {
    type : "org.nutz.dao.impl.NutDao",
    args : [{refer:'dataSource'}]
},
dataSource2:{
    type:"com.alibaba.druid.pool.DruidDataSource",
    events:{
       depose:"close"
    },
    fields:{
       url:"jdbc:mysql://192.168.0.239:3306/swdol?useUnicode=true",
       username:"root",
       password:"pass",
       maxActive:20,
       testWhileIdle:true,
       validationQuery:'SELECT COUNT(*) FROM SYS_DBTEST',
       removeAbandoned:true ,
       removeAbandonedTimeout:1800
    }
},
dao2 : {
    type : "org.nutz.dao.impl.NutDao",
    args : [{refer:'dataSource2'}]
}

}

为什么dataSource2里面没有driverClassName

validationQuery : "select 1"

选个 select count(*) from XXX 真是自己找事

是哦 我还没看到呢。。 validationQuery 不要去查业务表啦

额, 我改过来试试。。

PS: 如果不是mysql, 且数据库与服务器之间的通信稳定可靠, 可以不写validationQuery和testWhileIdle. 因为这两个主要是治mysql 8小时断连接的病

收到,解决了,3qqq

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