mysql-JDBC连接不到Mysql数据库

问题描述

JDBC连接不到Mysql数据库

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver '

The error may exist in file [D:WorkspaceMyGraduationDesign argetclassescomcyqookstoremappingUsersMapper.xml]

The error may involve com.cyq.bookstore.dao.UsersDao.selectByPrimaryKey

The error occurred while executing a query

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver '

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:76)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399)
at com.sun.proxy.$Proxy16.selectOne(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:165)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:69)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
at com.sun.proxy.$Proxy17.selectByPrimaryKey(Unknown Source)
at com.cyq.bookstore.serviceImpl.UsersServiceImpl.getUserById(UsersServiceImpl.java:19)
at TestMyBatis.test1(TestMyBatis.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:85)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:86)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:241)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Caused by: org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver '

The error may exist in file [D:WorkspaceMyGraduationDesign argetclassescomcyqookstoremappingUsersMapper.xml]

The error may involve com.cyq.bookstore.dao.UsersDao.selectByPrimaryKey

The error occurred while executing a query

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver '

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:386)
... 36 more

Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver '
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82)
at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68)
at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:315)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:75)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:61)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:102)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120)
... 43 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver '
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
... 53 more
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
... 57 more

解决方案

cannot load JDBC driver class 'com.mysql.jdbc.Driver
说的很清楚,没有找到mysql的jdbc的驱动自己检查下。

解决方案二:

1、JDBC的概念:JDBC:Java DataBase Connectivity 的缩写。java.sql包提供了JDBC API。JDBC API并不能直接访问数据库,它依赖于数据库厂商提供的JDBC Driver。2、java.sql包中常用的接口和类*Driver接口和DriverManager类:所有的JDBC驱动程序都必须实现Driver接口,驱动程序由数据库厂商编写,......
答案就在这里:如何通过JDBC连接MYSQL数据库(一)

解决方案三:

jar包是不是没有导入啊?

时间: 2024-10-29 16:53:09

mysql-JDBC连接不到Mysql数据库的相关文章

mysql-Eclipse用JDBC连接不上MYSQL

问题描述 Eclipse用JDBC连接不上MYSQL 使用JDBC的方法连接不上MySQL,我的网络是校园网,登陆后IP会变化,不知道这个对连接有没有什么影响,用的是mysql 5.6 以前用JDBC连接上过的,但是现在就不行了,不清楚原因,也在网上找过,但是找不到解决的办法,连接的JAR包是mysql-connector-java-5.1.26-bin.jar,提示错误Communication link failure, message from server: "Can't get hos

浅析MySQL JDBC连接配置上的两个误区

相信使用MySQL的同学都配置过它的JDBC驱动,多数人会直接从哪里贴一段URL过来,然后稍作修改就上去了,对应的连接池配置也是一样的,很少有人会去细想这每一个参数都是什么含义.今天我们就来聊两个比较常见的配置--是否要开启autoReconnect和是否缓存PreparedStatement. 一.autoReconnect=true真的好用么? 笔者看到过很多MySQL的URL里都是这样写的,复制过来改改IP.端口和库名就能用了: jdbc:mysql://xxx.xxx.xxx.xxx:3

Mysql JDBC驱动版本与Mysql版本的对应问题

Connector/J 5.1 支持Mysql 4.1.Mysql 5.0.Mysql 5.1.Mysql 6.0 alpha这些版本. Connector/J 5.0 支持MySQL 4.1.MySQL 5.0 servers.distributed transaction (XA). Connector/J 3.1 支持MySQL 4.1.MySQL 5.0 servers.MySQL 5.0 except distributed transaction (XA) support. Conn

JDBC 连接MySQL实例详解_Mysql

JDBC连接MySQL JDBC连接MySQL 加载及注册JDBC驱动程序 Class.forName("com.mysql.jdbc.Driver"); Class.forName("com.mysql.jdbc.Driver").newInstance(); JDBC URL 定义驱动程序与数据源之间的连接 标准语法: <protocol(主要通讯协议)>:<subprotocol(次要通讯协议,即驱动程序名称)>:<data so

mysql 数据连接教程

MySQL的连接 在您可以做任何事情与MySQL PHP中您必须先建立一个连接到您的网页主机的MySQL数据库.这样做是与MySQL的连接功能. MySQL localhost 如果您一直在围绕互联网的同时,你会知道, IP地址被用作标识符,用于计算机和网络服务器.在这个例子中的一个连接脚本,我们认为, MySQL的服务正在运行在同一台机器上的脚本. 当PHP脚本和MySQL是在同一台机器上,您可以使用本地的地址要连接到.本地是一个捷径,只要机器连接到本身.如果你的MySQL服务正在运行在一个单

MYSQL 左连接右连接和内连接的详解及区别_Mysql

MYSQL 左连接右连接和内连接的区别,这里就对这些概念经过一个实例,讲解清楚. 代码如下: drop table table1; CREATE TABLE `andrew`.`table1` ( `name` VARCHAR(32) NOT NULL, `city` VARCHAR(32) NOT NULL ) ENGINE = MyISAM; insert into TABLE1(name, city) values ('Person A', 'BJ'); insert into TABLE

vista 操作系统上使用JDBC连接mysql5.0

问题描述 我在mysql中建了数据库,也建了张表.可是在用myeclipse6.5写程序测试:packagetest;importjava.sql.*;publicclassConnTo{publicstaticvoidmain(String[]args){try{Class.forName("com.mysql.jdbc.Driver");System.out.println("successloadingmysqlDriver");}catch(Exceptio

mysql-初学JDBC连接MYSQL数据库,出现一个异常,求教,在线等

问题描述 初学JDBC连接MYSQL数据库,出现一个异常,求教,在线等 首先贴下拿来做试验的数据库,证明我数据库名没写错?d-7test 用户名,密码也没错耶 再来贴下代码: jar包也是加了的: 最后红条,报了这个错: 解决方案 Classpath中有没有包含你的mtsql驱动jar包? 解决方案二: getConnection里头不要写"url:"啊!,直接jdbc:mysql.... 解决方案三: 你的connect配置不对 解决方案四: 检查路径下有没有mysql-jdbc的j

jdbc连接mysql数据库驱动加载失败

问题描述 jdbc连接mysql数据库驱动加载失败 各位大神帮我看看这是啥意思,加载了驱动但还是报错啊 解决方案 右键build-path->add jars将lib下的驱动jar添加到类路径下,试试. 解决方案二: 已经解决了谢谢,好像是将jar包放在system jar里面 解决方案三: http://download.csdn.net/detail/be_proud/9301443 代码http://download.csdn.net/detail/be_proud/9301631 jar