Home  >  Article  >  Database  >  mysql对sql中别名引起的Columnnotfound问题_MySQL

mysql对sql中别名引起的Columnnotfound问题_MySQL

WBOY
WBOYOriginal
2016-06-01 12:59:571199browse

Caused by: java.sql.SQLException: Column ‘BTN_ICON’ not found.

报错信息是找不到表中的某字段,但是表里确确实实有这个字段。

这个问题,在百度是很难百度到的,因为百度出来的都是确实是字段有问题或者sql写的有问题。但其实,这个问题并不是sql或者表字段的问题

sql如下:

<code class="language-sql hljs ">SELECT B.RES_ID, B.RES_NAME, B.RES_TYPE, B.TARGET_RESOURCE, 
A.BTN_ICON AS RES_ICON,  A.BTN_SCRIPT AS RES_SCRIPT ,B.CREATE_TIME   
FROM tf_b_BUTTON A,tf_b_RES B</code>

我尝试把这个字段注释了,却报A.BTN_SCRIPT这个字段有问题,观察发现,<strong>仅仅用了别名的字段才有问题!</strong>

原因是,我升级了mysql的jar包。升级为mysql-connector-java-5.1.34.jar,升级的原因是我升级了tomcat(老的mysql的jar只支持tomcat7)。<br> 并且,我的数据源配置是:

url=”jdbc:mysql://130.51.2.24:3010/zplatdb”

应该改为就可以了:

url=”jdbc:mysql://130.51.2.24:3010/zplatdb?useUnicode=true&characterEncoding=UTF-8”

或者改为:

url=”jdbc:mysql://130.51.2.24:3010/zplatdb?characterEncoding=utf-8&useOldAliasMetadataBehavior=true”

注意:&符合要使用&;来替代。

问题解决。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn