有一个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. 配置VS Code+React开发环境

    1.安装node+npm 2.安装VS Code 3.选择工作区文件夹——右键点击在终端中打开 4.按照Using React in Visual Studio Code的文档进行操作 npm ins ...

  2. GitHub 总是打不开,网再好也米有用,怎么办?

    所用方法:修改host文件 一.键入网址:http://github.global.ssl.fastly.net.ipaddress.com/#ipinfo 拿到github.global.ssl.f ...

  3. Window常用且通用快捷键

    Ctrl系列: Ctrl +z :回撤,后退 Ctrl +a :全选 Alt系列: Alt+Tab :切换窗口 Window系列 Window+R:打开“运行”窗口 Window+D:显示桌面 其中常 ...

  4. JDK10源码分析之HashMap

    HashMap在工作中大量使用,但是具体原理和实现是如何的呢?技术细节是什么?带着很多疑问,我们来看下JDK10源码吧. 1.数据结构 采用Node<K,V>[]数组,其中,Node< ...

  5. MySQL 部署分布式架构 MyCAT (三)

    配置垂直分表 修改 schema.xml (db1) cd /data/mycat/conf cp schema.xml schema.xml.rwh # 修改配置 vi schema.xml < ...

  6. CodeForces - 1251B (思维+贪心)

    题意 https://vjudge.net/problem/CodeForces-1251B n个01串,可以任意交换任意两个字符串的字符任意次,问最多能有多少个回文串. 思路 分类讨论可以发现规律: ...

  7. 爬虫 xpath 获取方式

    回顾 bs4 实例化bs对象,将页面源码数据加载到该对象中 定位标签:find('name',class_='xxx') findall() select() 将标签中的文本内容获取 string t ...

  8. python session保持登录,新增地址,并删除,由观察可知,address_id决定删除的内容;

    import requests,reheaders={"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) Ap ...

  9. monkey参数

    一.参数分类 常规类参数:包括帮助参数和日志信息参数. 帮助类参数:monkey -h     -- 输出monkey命令使用指导 日志信息参数:monkey -v <event-count&g ...

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

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