Java连接MySQL数据库报错 java.sql.SQLException: Column 'xxxx' not found.问题解决

您所在的位置:网站首页 errornotfound的中文 Java连接MySQL数据库报错 java.sql.SQLException: Column 'xxxx' not found.问题解决

Java连接MySQL数据库报错 java.sql.SQLException: Column 'xxxx' not found.问题解决

2024-01-29 13:50| 来源: 网络整理| 查看: 265

一、问题

Java 执行 SQL 语句时,报错 java.sql.SQLException: Column 'user_name' not found. 但是在数据库客户端执行语句没有此问题。SQL语句如下: select id,user_name as name from user

二、环境

数据库版本:MySQL 5.1 JDBC驱动:mysql-connector-java 5.1.48 连接池配置:

driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/xxxx?useSSL=false&characterEncoding=utf8 username: xxxx password: xxxx 三、解决方案

原因是 Java 无法使用 MySQL 别名(as xxx)获取列,需要在连接池配置 url 加上 useOldAliasMetadataBehavior=true 也就是:

url: jdbc:mysql://localhost:3306/xxxx?useSSL=false&characterEncoding=utf8&useOldAliasMetadataBehavior=true


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3