问题描述
- Could not get JDBC Connection
-
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.microsoft.sqlserver.jdbc.SQLServerDriver'
The error may exist in cn/drzk/wanda/cinema/dao/form/dao/TicketsFromDao.java (best guess)
The error may involve cn.drzk.wanda.cinema.dao.form.dao.TicketsFromDao.count
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.microsoft.sqlserver.jdbc.SQLServerDriver'
解决方案
有没有引入SqlServer相关jar包 好像是sqljdbc.jar
解决方案二:
连接数据库失败,看看配置文件中的数据库名,用户名密码对不对
解决方案三:
刚才你不是发过贴了···
Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
SqlServer的驱动找不到
解决方案四:
这是一个配置文件模板,就是第二行,要配置数据库JDBC包路径,你找一下是不是这里的问题
<generatorConfiguration>
<classPathEntry location="数据库JDBC包路径"/>
<context id="项目id" targetRuntime="MyBatis3">
<plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"/>
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
<plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin"/>
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="数据库驱动" connectionURL="数据库URL" userId="数据库用户名" password="密码"/>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<javaModelGenerator targetPackage="目标包名" targetProject="目标路径">
<property name="enableSubPackages" value="false"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<sqlMapGenerator targetPackage="目标包名" targetProject="目标路径">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="目标包名" targetProject="目标路径">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>
<table tableName="表名" domainObjectName="Model类名"/>
</context>
</generatorConfiguration>
解决方案五:
代码就只是测试一下查询
测试类
@Autowired
private TicketsFromDao ticketsFromDao;
@Test
public void test6() {
System.out.println("business.decideTickets()===" + ticketsFromDao.count());
}
TicketsFromDao类
@Repository
public interface TicketsFromDao extends BaseFromDao {
@Select("exec sys.sp_readerrorlog 0, 1, 'listening'")
public long count() ;
@Select("select count(1) from Tickets")
public long countByCondition(Map<String, Object> prame) ;
@Select("select * from Tickets a where a.scanContent=#{scanContent}")
public List<Tickets> find(Map<String, Object> prame) ;
@Select("select * from Tickets a where a.scanContent=#{scanContent}")
public List<Tickets> findByDate(Map<String, String> prame) ;
}
解决方案六:
Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
明显找不到这个类啊,我去,1楼的人是怎么玩的?
解决方案七:
找不到这个类,你都不知道怎么做?我去,别再来问了.
时间: 2024-12-30 09:20:15