NutzCN Logo
问答 使用JS配置DAO时,driverClassName截取错误。
发布于 3133天前 作者 狠久 4089 次浏览 复制 上一个帖子 下一个帖子
标签:

dao.js配置如下:
```js
var ioc = {
dataSource: {
type: "com.alibaba.druid.pool.DruidDataSource",
events: {
depose: "close"
},
fields: {
url: "jdbc:mysql://localhost:3306/seekop?autoReconnect=true&failOverReadOnly=false&useUnicode=true&characterEncoding=utf8&useOldAliasMetadataBehavior=true",
username: "root",
password: "root",
testWhileIdle: true,
validationQuery: "select 1",
driverClassName: "com.mysql.jdbc.Driver",
maxActive: 100

    }
},
dao: {
    type: "org.nutz.dao.impl.NutDao",
    args: [{refer: "dataSource"}]
}

}

`` 这样配置后,发现driverClassName截取到的字符串是"com.mysql.jdbc.Driver",而不是com.mysql.jdbc.Driver`。然后就杯具了……
有出现过这样的问题吗?

13 回复

完整报错信息

java.sql.SQLException: "com.mysql.jdbc.Driver", at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:550) at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:649) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:991) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:987) 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:106) at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:177) at org.nutz.dao.impl.NutDao.<init>(NutDao.java:112) at org.nutz.dao.util.DaoUp.setDataSource(DaoUp.java:131) at org.nutz.dao.util.DaoUp.init(DaoUp.java:189) at org.nutz.dao.util.DaoUp.init(DaoUp.java:170) at com.trioly.server.TaskThread.main(TaskThread.java:50) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Caused by: java.lang.ClassNotFoundException: "com.mysql.jdbc.Driver", at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:191) at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:548) ... 17 more Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: "com.mysql.jdbc.Driver", at org.nutz.lang.Lang.wrapThrow(Lang.java:153) at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:113) at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:177) at org.nutz.dao.impl.NutDao.<init>(NutDao.java:112) at org.nutz.dao.util.DaoUp.setDataSource(DaoUp.java:131) at org.nutz.dao.util.DaoUp.init(DaoUp.java:189) at org.nutz.dao.util.DaoUp.init(DaoUp.java:170) at com.trioly.server.TaskThread.main(TaskThread.java:50) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Caused by: java.sql.SQLException: "com.mysql.jdbc.Driver", at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:550) at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:649) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:991) at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:987) 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:106) ... 11 more Caused by: java.lang.ClassNotFoundException: "com.mysql.jdbc.Driver", at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:191) at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:548) ... 17 more

@wendal

java.sql.SQLException: "com.mysql.jdbc.Driver",
	at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:550)
	at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:649)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:991)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:987)
	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:106)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:177)
	at org.nutz.dao.impl.NutDao.<init>(NutDao.java:112)
	at org.nutz.dao.util.DaoUp.setDataSource(DaoUp.java:131)
	at org.nutz.dao.util.DaoUp.init(DaoUp.java:189)
	at org.nutz.dao.util.DaoUp.init(DaoUp.java:170)
	at com.trioly.server.TaskThread.main(TaskThread.java:50)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: "com.mysql.jdbc.Driver",
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:191)
	at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:548)
	... 17 more
Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: "com.mysql.jdbc.Driver",
	at org.nutz.lang.Lang.wrapThrow(Lang.java:153)
	at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:113)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:177)
	at org.nutz.dao.impl.NutDao.<init>(NutDao.java:112)
	at org.nutz.dao.util.DaoUp.setDataSource(DaoUp.java:131)
	at org.nutz.dao.util.DaoUp.init(DaoUp.java:189)
	at org.nutz.dao.util.DaoUp.init(DaoUp.java:170)
	at com.trioly.server.TaskThread.main(TaskThread.java:50)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.sql.SQLException: "com.mysql.jdbc.Driver",
	at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:550)
	at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:649)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:991)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:987)
	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:106)
	... 11 more
Caused by: java.lang.ClassNotFoundException: "com.mysql.jdbc.Driver",
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:191)
	at com.alibaba.druid.util.JdbcUtils.createDriver(JdbcUtils.java:548)
	... 17 more

把这一行注释掉试试,我猜根本没读这个js文件

driverClassName: "com.mysql.jdbc.Driver",

@wendal
注释掉这句后,就报下面的错误了:

java.sql.SQLException: unkow jdbc driver : "jdbc:mysql://localhost:3306/seekop?autoReconnect=true&failOverReadOnly=false&useUnicode=true&characterEncoding=utf8&useOldAliasMetadataBehavior=true",
	at com.alibaba.druid.util.JdbcUtils.getDriverClassName(JdbcUtils.java:436)
	at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:643)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:991)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:987)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:103)
Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: unkow jdbc driver : "jdbc:mysql://localhost:3306/seekop?autoReconnect=true&failOverReadOnly=false&useUnicode=true&characterEncoding=utf8&useOldAliasMetadataBehavior=true",
	at org.nutz.trans.Trans.getConnectionAuto(Trans.java:263)
	at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:106)
	at org.nutz.lang.Lang.wrapThrow(Lang.java:153)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:177)
	at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:113)
	at org.nutz.dao.impl.NutDao.<init>(NutDao.java:112)
	at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:177)
	at org.nutz.dao.util.DaoUp.setDataSource(DaoUp.java:131)
	at org.nutz.dao.util.DaoUp.init(DaoUp.java:189)
	at org.nutz.dao.impl.NutDao.<init>(NutDao.java:112)
	at org.nutz.dao.util.DaoUp.init(DaoUp.java:170)
	at org.nutz.dao.util.DaoUp.setDataSource(DaoUp.java:131)
	at org.nutz.dao.util.DaoUp.init(DaoUp.java:189)
	at org.nutz.dao.util.DaoUp.init(DaoUp.java:170)
	at com.trioly.server.TaskThread.main(TaskThread.java:50)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)	at com.trioly.server.TaskThread.main(TaskThread.java:50)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.sql.SQLException: unkow jdbc driver : "jdbc:mysql://localhost:3306/seekop?autoReconnect=true&failOverReadOnly=false&useUnicode=true&characterEncoding=utf8&useOldAliasMetadataBehavior=true",
	at com.alibaba.druid.util.JdbcUtils.getDriverClassName(JdbcUtils.java:436)
	at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:643)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:991)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:987)
	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:106)
	... 11 more

用的是myeclipse?是不是统统被转义了? 用notepad++打开这个js文件看看真实的内容

@wendal
这个是我在调试的时候情况:
FAEEB367-4F29-4F28-A879-C5FA9C690CC0_png

@wendal
用的是IDEA,用Sublime看了一下:
F58B0628-2809-4D28-A2EB-F6F2423EA24C_png

用maven了?打包个war, 看看里面的配置文件是不是转义了

@wendal 没有用,就是普通工程,我打了WAR包看了一下: 94751655-DCC0-48E7-8D8F-D1C975EC4582_png

js文件里咋不用单引号呢?

@qq_9b4d7246 替换了试了一下,没有用,还是一样的问题

检查下 druid 和 mysql jdbc驱动的版本是否对应

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