mybatis配置,idea报错:java.sql.SQLException: No suitable driver found for jdbc://localhost:3306/mybatis_test

报错信息:

"C:\Program Files\Java\jdk1.8.0_211\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4\lib\idea_rt.jar=54826:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_211\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_211\jre\lib\rt.jar;D:\file\java_web_dev\IdeaProject\mybatis_test\target\test-classes;D:\file\java_web_dev\IdeaProject\mybatis_test\target\classes;E:\software\mysql\mysql-8.0.18-winx64\mysql-connector-java-8.0.18.jar;C:\Users\lonelyisland\.m2\repository\org\mybatis\mybatis\3.5.4\mybatis-3.5.4.jar;C:\Users\lonelyisland\.m2\repository\mysql\mysql-connector-java\8.0.18\mysql-connector-java-8.0.18.jar;C:\Users\lonelyisland\.m2\repository\com\google\protobuf\protobuf-java\3.6.1\protobuf-java-3.6.1.jar;C:\Users\lonelyisland\.m2\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar;C:\Users\lonelyisland\.m2\repository\junit\junit\4.11\junit-4.11.jar;C:\Users\lonelyisland\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar" com.syz.test.MybatisTest
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Loading class `com.mysql.jdbc.Driver‘. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver‘. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: java.sql.SQLException: No suitable driver found for jdbc://localhost:3306/mybatis_test
### The error may exist in com/syz/dao/IUserDao.xml
### The error may involve com.syz.dao.IUserDao.findAll
### The error occurred while executing a query
### Cause: java.sql.SQLException: No suitable driver found for jdbc://localhost:3306/mybatis_test
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
	at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
	at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:144)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
	at com.sun.proxy.$Proxy0.findAll(Unknown Source)
	at com.syz.test.MybatisTest.main(MybatisTest.java:30)
Caused by: java.sql.SQLException: No suitable driver found for jdbc://localhost:3306/mybatis_test
	at java.sql.DriverManager.getConnection(DriverManager.java:689)
	at java.sql.DriverManager.getConnection(DriverManager.java:208)
	at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:221)
	at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:216)
	at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:95)
	at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:422)
	at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89)
	at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:138)
	at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60)
	at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
	at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)
	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
	... 7 more

Process finished with exit code 1

idea链接mysql数据库见下面参考链接1,需要注意的一点,如果数据库没有设置全局的serverTimeZone这里报错,然后去哪个设置页面Advanced那里把该项写为Asia/Shanghai就ok,idea连接后可以在右侧看到如图所示效果

然后尝试连接后并未解决问题(尴尬XD 这步只是起到了数据库连接工具,感觉这个功能集成了datagrip的一些特性),再找其他方法

关键报错是这句话:

参考链接2也列了几种可能得错误。。。也不是

参考链接3终于解决,算是一个非常低级的错误。。。写SqlMapConfig.xml的时候

错误写法

<property name="url" value="jdbc:mysql//localhost:3306/mybatis_test"/>

正确写法,注意有冒号。。。

<property name="url" value="jdbc:mysql://localhost:3306/mybatis_test"/>

算是一个教训,也是一个no suitable driver found for jdbc的一个解决汇总

另外,如果数据库没有设置全局serverTimeZone,这里还可能报个错,一个简单的解决是在url后?加上一些参数(包括时区)

<property name="url" value="jdbc:mysql://localhost:3306/mybatis_test?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT"/>

还有一个地方注意,xml中的&必须写为&否则这里报错

再改:

<property name="url" value="jdbc:mysql://localhost:3306/mybatis_test?useUnicode=true&amp;characterEncoding=utf8&amp;serverTimezone=GMT"/>

到这里我出现的关于idea数据库,以及mybatis数据库配置出现的问题全部解决,小结如下:

  • mybatis出现就是为了解决jdbc配置问题,让使用者更加专注于问题本身,但是配置过程需小心(也是我不熟悉配置的原因,use it or lose it,慢慢熟悉)
  • 配置文件SqlMapConfig.xml中url需要注意"mysql:"的":"
  • xml文件中的";"需要用"&"代替

参考:

idea链接mysql数据库

No Suitable Driver Found For Jdbc 解决方法

mybatis遇到的问题----没有合适的驱动(No suitable driver found for jdbc)

server.xml; lineNumber: 44; columnNumber: 95; 对实体 "characterEncoding" 的引用必须以 ‘;‘ 分隔符结尾。

异常:java.sql.SQLException: The server time zone value ‘?й???????‘ is unrecognized or represents more

原文地址:https://www.cnblogs.com/lonelyisland/p/12677074.html

时间: 2024-10-22 11:26:42

mybatis配置,idea报错:java.sql.SQLException: No suitable driver found for jdbc://localhost:3306/mybatis_test的相关文章

java.sql.SQLException:No suitable driver found for http://localhost:3306/school

1.错误描述 2.错误原因 Class.forName("com.mysql.jdbc.Driver"); Connection conn = null; Statement stat = null; ResultSet rs = null; try { conn = DriverManager.getConnection("http://localhost:3306/school", "root", "root"); sta

关于初次使用java jdbc遇到数据库连接不上的问题java.sql.SQLException: No suitable driver found for jdbc:mysql://127.0.0.1:3306/test

首先我们写java有很大一部分的程序员使用的是神器ecplise 那我晒晒我写的ecplise有错误的代码(其实并不是代码错误了) 就类似这样的代码,首先你需要安装mysql在你的电脑上root就是用户名,密码当然就是你设置的密码 然后我们就会出现这样的错误信息 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 

java.sql.SQLException: No suitable driver found for jdbc:hive://localhost:10000/default

error: java.sql.SQLException: No suitable driver found for jdbc:hive://localhost:10000/default at java.sql.DriverManager.getConnection(DriverManager.java:596) at java.sql.DriverManager.getConnection(DriverManager.java:233) at demo.utils.JDBCUtils.get

【异常】java.sql.SQLException: No suitable driver found for jdbc://mysql://hadoop001:3306/xxx

IDEA程序代码中需要访问mysql,出现 java.sql.SQLException: No suitable driver found for jdbc://mysql://hadoop001:3306/ruoze_g6 有可能是驱动没加进来,有可能是连接地址url写错了. 需要在pom中加上mysql驱动: <dependency>      <groupId>mysql</groupId>      <artifactId>mysql-connect

java连接sqlserver2008报错 java.sql.SQLException: 对象名 &#39;表名&#39; 无效.

注意:c3p0的数据库配置方式为: <named-config name="sqlsvr"> <property name="driverClass">net.sourceforge.jtds.jdbc.Driver</property> <property name="jdbcUrl">jdbc:jtds:sqlserver://localhost:1433/WaterNet_DaFeng<

连接mysql报错java.sql.SQLException: The server time zone value &#39;?й???????&#39; is unrecognized...解决方法

报错内容: java.sql.SQLException: The server time zone value '?й???????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time

JSP页面无法使用JSP导致Mysql驱动无法找到&quot;java.sql.SQLException: No suitable driver found for ${snapshot}&quot;

这个问题折腾了半天,老以为是Mysql驱动的问题,还好最后偶然发现了是EL表达式识别不了报错javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for ${snapshot}" 问题: <!DOCTYPE web-ap

出现java.sql.SQLException: No suitable driver的几种解决办法

今天在用C3p0连接MySql数据库 这个时候出现了上面的错误, 一般来说这种错误有3个方向解决 一般都是db的配置的问题 ,一定要小心DB 的配置 八月 19, 2017 8:30:46 下午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run警告: [email protected]95 -- Acquisition Attempt Failed!!! Clearing pending acquires. While t

java.sql.SQLException: No suitable driver 问题解决

最近在学习java,用到c3p0数据库连接池,遇到一个很奇怪的现象,用main方法测试是可以正常连接数据库的,但是使用jsp调用代码,就会报如下图的错误! 最下面的java.sql.SQLException: No suitable driver才是重点 解决办法是将mysql的驱动jar包,放到D:\Program Files\Java\jdk1.8.0_91\jre\lib\ext目录下(JAVA_HOME目录下的jre\lib\ext目录下) 然后就解决了这个问题