【发布时间】:2015-07-09 09:21:54
【问题描述】:
我使用Spring+Mybatis 并尝试在 Centos 中连接 mysql server 5.1。
mysqldatabase的连接没问题,我用Test Class测试时没有问题。
在Window Server中使用相同配置连接MYSQL5.5时没有问题。
在 Centos 连接 MYSQL5.1 时, 当我的 web 应用项目进行 select 查询时,发生了异常。
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'nmnl.USR' doesn't exist
我该如何解决?
这是 spring-beans.xml 中的配置。
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<util:properties id="SQL_ERROR_CODE" location="classpath:SQL_ERROR_CODE.properties" />
<util:properties id="APPLICATION_CONFIG" location="classpath:APPLICATION_CONFIG.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://192.168.0.99:3306/nmnl?useUnicode=yes&characterEncoding=UTF-8" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:sqlmap-config.xml" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
【问题讨论】:
-
用 POJO 检查你的表映射。还要检查数据库中是否有表。
-
表映射,POJO和表存在。使用主类(JDBC)进行测试时已经可以了。我认为这将是我的 batis 的原因。
-
我的意思是检查表映射是否有错字
标签: java mysql linux spring mybatis