hibernate createSQLQuery StringIndexOutOfBoundsException: String index out of range: 0
有一个sql用union拼接的如下:
select id,(**还有很多字段**),'' as NewName from tb1
union
select id,(**还有很多字段**),name as NewName from tb2
union
select id,(**还有很多字段**),name as NewName from tb3
tb1表中不存在这个字段所以用'' as NewName
tb2,tb3中有这了个字段是varchar的
查询以一直报错:StringIndexOutOfBoundsException: String index out of range: 0
1.但是每个select单独查询完全没问题 ,开始以为是union的问题,
2.去掉NewName 这个字段后也没问题,.以为是sql太长了,
3.解决:最后网上查是因为:处理方法 数据表字段为char导致,修改为VARCHAR. 建表时不要使用char类型,为null就会报以上错误
原因是tb1中:'' as NewName以为是char而下面有数据的是varchar所以union的时候类型不一样就会报错。
最后把: '' as NewName 改成 null as NewName
改完成SQL如下,搞定:
select id,(**还有很多字段**),null as NewName from tb1
union
select id,(**还有很多字段**),name as NewName from tb2
union
select id,(**还有很多字段**),name as NewName from tb3
和上面相反的问题
hibernate createSQLQuery报错: MappingException: No Dialect mapping for JDBC type: 0
有SQL,只有一个select:
select id,(**还有很多字段**),null as isVisit from Table 报错MappingException: No Dialect mapping for JDBC type: 0 (isVist数据库中不存在这个字段)把: null as isVisit 改成 null as isVisit 搞定:
select id,(**还有很多字段**),'' as isVisit from Table
hibernate createSQLQuery StringIndexOutOfBoundsException: String index out of range: 0的更多相关文章
- java.lang.StringIndexOutOfBoundsException: String index out of range: 0
hibernet 报错 java.lang.StringIndexOutOfBoundsException: String index out of range: 0 处理方法 数据表字段为char ...
- Spring Boot 启动报错 Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 37
使用命令 java -jar springBoot.jar 启动项目,结果报错如下: Exception at java.lang.String.substring(String.java:) at ...
- tk.mybatis 报错:tk.mybatis.mapper.MapperException: tk.mybatis.mapper.MapperException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'apiLogMapper ...
- IndexError:string index out of range
IndexError:string index out of range 出现在下标越界的情况,如 item[1],可能为空的时候下标就会越界
- mac安装MySQLdb:IndexError: string index out of range
使用mac安装MySQLdb的时候出现string index out of range 大概的错误是这样的: 然后尝试手动安装,我下载了包后,依然出现这个错误. 于是百度了下: https://ww ...
- java.sql.SQLException:Column Index out of range,0<1
1.错误描述 java.sql.SQLException:Column Index out of range,0<1 2.错误原因 try { Class.forName("com.m ...
- MacOS 安装MysqlDB 问题解决方案( 解决 IndexError: string index out of range)
pip install MySQL-python时报错如下: Command "python setup.py egg_info" failed with error code 1 ...
- Mac安装Mysql-python遇到的坑,被这俩报错反复摩擦:'my_config.h' file not found 和 IndexError: string index out of range
最后Stackoverflow上面的大神解决了问题: Link brew install mysql brew unlink mysql brew install mysql-connector-c ...
- java.sql.SQLException: Parameter index out of range (0 < 1 ).
向SQL中传入数据是从1开始的!!! 从ResultSet中取数据也是从1开始的!
随机推荐
- matlab C程序
通过把耗时长的函数用c语言实现,并编译成mex函数可以加快执行速度 Matlab本身是不带c语言的编译器的,所以要求你的机器上已经安装有VC,BC或Watcom C中的一种 注:在Matlab里,矩阵 ...
- RdKafka文档翻译
函数string rd_kafka_err2str ( integer $err ) 将rdkafka错误代码转换为字符串 integer rd_kafka_errno2err ( integer $ ...
- windows双网卡绑定
windows双网卡绑定 开门贱山: 以下内容纯属抄袭,如有雷同,也是醉了~~!! ————————————— ...
- Python—序列化和反序列化模块(json、pickle和shelve)
什么是序列化 我们把对象(或者变量)从内存中变为可存储或者可传输的过程称为序列化.在python中为pickling,在其他语言中也被称之为serialization,marshalling,flat ...
- Linux—主机扫描工具(Nmap)
Nmap包含五项基本功能: 主机探测 (Host Discovery) 端口扫描 (Port Scanning) 版本检测 (Version Detection) 操作系统侦测 (Operating ...
- Linux 登录 MySQL 报错, 解决bash: mysql: command not found 的方法
原因:这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,当然会找不到命令,我们需要做的就是映射一个链接到/usr/bin目录下,相当于建立一个链接文件. 首先得知道mysql ...
- CodeForces - 1251E2 (思维+贪心)
题意 https://vjudge.net/problem/CodeForces-1251E2 一共有 n 个选民,你可以付出 pi 的代价让第 i 个选民为你投票,或者,在为你投票的人数达到 mi ...
- 4. Vue - 指令(Add)
一.指令系统 1. v-text v-text主要用来更新textContent,可以等同于JS的text属性. <span v-text="msg"></s ...
- 面试必备的13道可以举一反三的Vue面试题
Vue框架部分我们会涉及一些高频且有一定探讨价值的面试题,我们不会涉及一些非常初级的在官方文档就能查看的纯记忆性质的面试题,比如: * vue常用的修饰符? * vue-cli 工程常用的 n ...
- 201871010111-刘佳华《面向对象程序设计(java)》第十六周学习总结
学号-姓名<面向对象程序设计(java)>第十六周学习总结 实验十四 应用程序归档与线程初步 实验时间 2019-12-12 第一部分:理论知识总结 1.程序与进程的概念 ‐程序是一段静 ...