ava.lang.RuntimeException: java.sql.SQLException: No suitable driver found for jdbc:mysql://127.0.0.1:3306/nutzdemo?useUnicode=true&characterEncoding=utf-8
at org.nutz.lang.Lang.wrapThrow(Lang.java:181)
at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:113)
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:101)
16 回复
group 'test'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.nutz', name: 'nutz', version: '1.r.60'
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.40'
// https://mvnrepository.com/artifact/com.alibaba/druid
compile group: 'com.alibaba', name: 'druid', version: '1.1.0'
}
export 的资源文件没编译过来?
来自美丽的 NutzCN
还有什么别的解决办法吗??用Class.forName可以正常的连接数据库,但是用SimpleDataSource就报如下错误
错误代码如下
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://127.0.0.1/nutzdemo
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at org.nutz.dao.impl.SimpleDataSource.getConnection(SimpleDataSource.java:42)
at org.nutz.trans.Trans.getConnectionAuto(Trans.java:263)
at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:106)
功能代码
try {
// 创建一个数据源
SimpleDataSource dataSource = new SimpleDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1/nutzdemo");
dataSource.setUsername("root");
dataSource.setPassword("123456");
// 创建一个NutDao实例,在真实项目中, NutDao通常由ioc托管, 使用注入的方式获得.
Dao dao = new NutDao(dataSource);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
```
try {
// 创建一个数据源
SimpleDataSource dataSource = new SimpleDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1/nutzdemo");
dataSource.setUsername("root");
dataSource.setPassword("123456");
// 创建一个NutDao实例,在真实项目中, NutDao通常由ioc托管, 使用注入的方式获得.
Dao dao = new NutDao(dataSource);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
添加回复
请先登陆