【问题标题】:Can't connect to mysql in centoscentos无法连接mysql
【发布时间】: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&amp;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


【解决方案1】:

请检查 nmnl 数据库中是否存在表 USR。因为异常说在 nmnl 中不存在表 USR。

【讨论】:

    【解决方案2】:

    是的。我知道了。 当我使用查询恢复数据库时,我的查询是 CREATE USR。 我删除了这个 char ` 并恢复。

    我把所有的表名都改成了大写。

    【讨论】:

      【解决方案3】:

      我卖了。 Linux 中的 MySQL 区分大小写。只能选择上或下。我在 mybatis sql map 中的查询是低位和高位。所以我全部改成了大写。

      【讨论】:

        猜你喜欢
        • 2016-04-13
        • 1970-01-01
        • 2014-10-30
        • 1970-01-01
        • 2019-08-17
        • 1970-01-01
        • 1970-01-01
        • 2023-03-06
        • 2014-03-27
        相关资源
        最近更新 更多