Error querying database when attempting to run MyBatis.

367 views
Skip to first unread message

Ryan Conklin

unread,
Nov 15, 2012, 6:52:02 PM11/15/12
to mybati...@googlegroups.com
The error I get is below, farther down I have included my code and my "MapperConfig.xml". I get this error when I attempt to debug, I have confirmed my "com.mysql.jdbc.Driver" is correct on the .xml config sheet.


org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.jdbc.Driver
### The error may exist in mybatis/res/AddressesMapper.xml
### The error may involve org.mybatis.generator.AddressesMapper.selectByPrimaryKey
### The error occurred while executing a query
### Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.jdbc.Driver




<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://10.10.12.35:3306/"/>
<property name="username" value="********"/>
<property name="password" value="*********"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mybatis/res/AddressesMapper.xml"/>
</mappers>
</configuration>




------------------------------------------------------------------

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.InputStream;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
import org.mybatis.generator.Addresses;
import org.mybatis.generator.AddressesMapper;



/**
 *
 * @author Ryan
 */
public class MyBatis {
    
     //log4j setup
    static Logger logger = Logger.getLogger("MyBatis.class");
      
    

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
             
            BasicConfigurator.configure();
            logger.info("MyBatis Running");
            
        try {
              String mapconfig = "mybatis/res/MapperConfig.xml";
              
              InputStream inputStream = Resources.getResourceAsStream(mapconfig);
              SqlSessionFactory sqlSession = new SqlSessionFactoryBuilder().build(inputStream);
              
        
            
              SqlSession session = sqlSession.openSession();
        try {
              AddressesMapper mapper = session.getMapper(AddressesMapper.class);
              Addresses addresses = mapper.selectByPrimaryKey(101);
            } finally {
              session.close();
            }
                
    }

     catch( Exception ex) {
            ex.printStackTrace();
        }
    }
}  
Reply all
Reply to author
Forward
0 new messages