有一个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的更多相关文章

  1. java.lang.StringIndexOutOfBoundsException: String index out of range: 0

    hibernet 报错 java.lang.StringIndexOutOfBoundsException: String index out of range: 0 处理方法  数据表字段为char ...

  2. 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 ...

  3. 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 ...

  4. IndexError:string index out of range

    IndexError:string index out of range 出现在下标越界的情况,如 item[1],可能为空的时候下标就会越界

  5. mac安装MySQLdb:IndexError: string index out of range

    使用mac安装MySQLdb的时候出现string index out of range 大概的错误是这样的: 然后尝试手动安装,我下载了包后,依然出现这个错误. 于是百度了下: https://ww ...

  6. 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 ...

  7. MacOS 安装MysqlDB 问题解决方案( 解决 IndexError: string index out of range)

    pip install MySQL-python时报错如下: Command "python setup.py egg_info" failed with error code 1 ...

  8. 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 ...

  9. java.sql.SQLException: Parameter index out of range (0 < 1 ).

    向SQL中传入数据是从1开始的!!! 从ResultSet中取数据也是从1开始的!

随机推荐

  1. HTTP协议解析之Cookie

    " Cookie与身份认证." 提到HTTP协议,不可避免地都会牵涉到Cookie,可以说,Cookie作为HTTP的重要组成部分,促进了HTTP协议的发展壮大. HTTP协议如果 ...

  2. [转]Eclipse插件开发之基础篇(6) SWT简介

    原文地址:http://www.cnblogs.com/liuzhuo/archive/2010/09/01/eclipse_plugin_1_3_1.html SWT(Standard Widget ...

  3. [转]JVM系列一:JVM内存组成及分配

    原文地址:http://www.cnblogs.com/redcreen/archive/2011/05/04/2036387.html JVM系列一:JVM内存组成及分配 java内存组成介绍:堆( ...

  4. MSSQL添加外键

    alter table 需要建立外键的表 with check/nocheck add constraint 外键名字 foreign key (需要建立外键的字段名) references 外键表( ...

  5. 4-8 pie与布局

    In [1]: %matplotlib inline import matplotlib.pyplot as plt   1.pie简单参数:plt.pie(x, explode=None, labe ...

  6. C++学习五 const vector<int>类型的迭代器使用

    一情景: 算法功能:对于传入的vector, 能够找到两个数字,使其相加之和为target,然后返回这两个数字的位置(也就是秩) 最开始是这样的一个问题: 对于一个传入的const vector< ...

  7. 用一个例子说明oracle临时表,创建过程,

    --创建临时表,规定好格式,是必须的,不同于sqlserver那么随意: Create Global Temporary Table record4 (   yljgdm VARCHAR2(22) n ...

  8. CF1225A Forgetting Things

    CF1225A Forgetting Things 洛谷评测传送门 题目描述 Kolya is very absent-minded. Today his math teacher asked him ...

  9. URL、URI、URN之间的区别

    URL统一资源定位符 URI统一资源标识符 URN统一资源名称 URL是URI的一个特例. URI由URL和URN两部分组成. 在java类中,URI类不包含任何访问资源的方法,它唯一的作用就是解析. ...

  10. angular 多路由模块新建组件的方法

    More than one module matches. Use skip-import option to skip importing the component into the closes ...