java.sql.SQLException: Fail to convert to internal representation

message: "Error attempting to get column 'PARAM_NAME' from result set. 
Cause: java.sql.SQLException: Fail to convert to internal representation↵; 
uncategorized SQLException; SQL state [99999]; error code [17059];
 Fail to convert to internal representation; 
nested exception is java.sql.SQLException: 
Fail to convert to internal representation"

 

Java

package com.app.dto;



public class DiversityCustomAttrDTO {

    private Long numberValue;

    private String paramName;



    public DiversityCustomAttrDTO(Long numberValue, String paramName) {

       this.numberValue = numberValue;

       this.paramName = paramName;

    }



// getters setters

}

 

MyBatis

<resultMap id="customAttrResultMap" type="com.app.dto.DiversityCustomAttrDTO">

    <result property="paramName" column="PARAM_NAME" jdbcType="VARCHAR"/>

    <result property="numberValue" column="NUMBER_VALUE" jdbcType="NUMERIC" />

</resultMap>

 

怎么看都没问题,删掉代码一行行加回来,原来是IDEA自动生成构造函数的参数顺序和resultset里result顺序不匹配时就会报错。

删掉构造函数 - 工作

加上默认无参的构造函数 - 工作

调整参数顺序和resultset里一样 - 工作

 

那么基本可以推测,mybatis ibatis 源码里当遇到有构造函数的时候,而且有没有无参的构造函数,参数顺序就必须和resultset里是一致的。

推测底层是通过反射来实例化的,看下反射类中的Constructor,只能拿到

private Class<?>[] parameterTypes;

所以当我们的构造函数第一个是long,而result里是varchar,也就是String时,就报错了。

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
java.sql.SQLException: Connection refused: connect是一个常见的错误,它意味着无法建立数据库连接。这个错误通常出现在以下几种情况下: 1. 数据库服务器未启动或连接不可用。请确保数据库服务器正在运行,并且端口号和连接地址正确。 2. 防火墙或网络设置阻止了数据库连接。请检查防火墙设置,确保允许您的程序与数据库进行通信。 3. 数据库配置错误。请检查您的数据库连接配置,确保用户名、密码和数据库名称正确,并且驱动程序已正确加载。 4. 数据库连接池问题。如果您正在使用连接池来管理数据库连接,可能是连接池配置问题导致连接被拒绝。请检查连接池配置,并确保连接池中有足够的可用连接。 解决这个问题的方法包括: 1. 检查数据库服务器是否正在运行,并确保连接地址和端口号正确。 2. 检查防火墙和网络设置,确保允许数据库连接。 3. 检查数据库连接配置,确保用户名、密码和数据库名称正确,并且驱动程序已正确加载。 4. 如果使用连接池,检查连接池配置,确保连接池中有足够的可用连接。 如果以上方法都没有解决问题,您可以尝试重新启动数据库服务器,或者联系数据库管理员以获取进一步的帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [java.sql.SQLException: 结果集已耗尽](https://download.csdn.net/download/weixin_38669628/11462246)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [java.sql.SQLException: Io 异常: Connection refused](https://blog.csdn.net/cuihuang1302/article/details/100436833)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值