本文转自  https://www.cnblogs.com/yingsong/p/5685790.html

原 因:某一个字段本为varchar2(1024),但是实际要插入的值超过varchar2允许的最大长度4000时,oracle自动将该字段值转化为Long类型,然后提示插入操作失败。

解决办法:

    1)是不是真的要插入超过定义长度的值?否则对长度做判断,截取等。

    2)若是,则将字段采用clob、blob,或者使用文件代替,字段保存文件地址即可。

对于clob、blob

CLOB 定义

  数据库中的一种保存文件所使用的类型。

  Character Large Object

  SQL 类型 CLOB 在 JavaTM 编程语言中的映射关系。SQL CLOB 是内置类型,它将字符大对象 (Character Large Object) 存储为数据库表某一行中的一个列值。默认情况下,驱动程序使用 SQL locator(CLOB) 实现 Clob 对象,这意味着 CLOB 对象包含一个指向 SQL CLOB 数据的逻辑指针而不是数据本身。Clob 对象在它被创建的事务处理期间有效。

  在一些数据库系统里,也使用Text 作为CLOB的别名,比如SQL Server

BLOB的含义

  BLOB (binary large object),二进制大对象,是一个可以存储二进制文件的容器。

  在计算机中,BLOB常常是数据库中用来存储二进制文件的字段类型。

  BLOB是一个大文件,典型的BLOB是一张图片或一个声音文件,由于它们的尺寸,必须使用特殊的方式来处理(例如:上传、下载或者存放到一个数据库)。

  根据Eric Raymond的说法,处理BLOB的主要思想就是让文件处理器(如数据库管理器)不去理会文件是什么,而是关心如何去处理它。

但也有专家强调,这种处理大数据对象的方法是把双刃剑,它有可能引发一些问题,如存储的二进制文件过大,会使数据库的性能下降。在数据库中存放体积较大的多媒体对象就是应用程序处理BLOB的典型例子。

CLOB和BLOB的区别

  CLOB使用CHAR来保存数据。 如:保存XML文档。

BLOB就是使用二进制保存数据。 如:保存位图。

 

JAVA里面对CLOB的操作

  在绝大多数情况下,使用2种方法使用CLOB

  1 相对比较小的

    可以用String进行直接操作,把CLOB看成字符串类型即可

  2 如果比较大

    1)如果使用jdbc则,可以用 getAsciiStream 或者 getUnicodeStream 以及对应的 setAsciiStream 和 setUnicodeStream 即可)

    2)clob怎么和Hibernate一起使用(参考原文:http://www.tuicool.com/articles/fumQfe )

      a)Clob类型的属性的赋值方式—— String转Clob :

        String content = request.getParameter("content");//1.从request请求中取值(String类型的)
        Clob clob = Hibernate.createClob(content);//2.通过hibernate将string转化为clob
        news.setContent(clob);//3.给实体类对应属性赋值

      b)Clob类型的属性的取值方式—— Clob转String :

        List<News> list = query.addEntity(News.class).list();//1.从数据库取值
        News news = (News)list.get(0);//2.取News对象
        String content = ClobUtil.ClobToString(news.getContent());//3.将news对象中的clob类型的content转化为String字符串
      
 1 -----------------   ClobUtil    -----------------------
2
3 public class ClobUtil {
4 public static String ClobToString(Clob clob) {
5 String clobStr = "";
6 Reader is = null;
7 try {
8 is = clob.getCharacterStream();
9 // 得到流
10 BufferedReader br = new BufferedReader(is);
11 String s = null;
12 s = br.readLine();
13 StringBuffer sb = new StringBuffer();
14 //执行循环将字符串全部取出赋值给StringBuffer,由StringBuffer转成String
15 while (s != null) {
16 sb.append(s);
17 s = br.readLine();
18 }
19 clobStr = sb.toString();
20 } catch (IOException e) {
21 e.printStackTrace();
22 } catch (SQLException e) {
23 e.printStackTrace();
24 }
25 return clobStr;
26 }
27 }
28
29 注意:通过流的方式读取Clob类型数据

SQL state [72000]; error code [1461]; ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值 ; nested exception is java.sql.BatchUpdateException: ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值的更多相关文章

  1. nested exception is java.sql.SQLException: Cannot convert value '0000-00-00 00:00:00' from column 14 to TIMESTAMP.

    无法将"0000-00-00 00:00:00"转换为TIMESTAMP 2017-05-08 00:56:59 [ERROR] - cn.kee.core.dao.impl.Ge ...

  2. 线上问题 - MySQL SQL state [HY000]; error code [1366]

    一.问题描述 另外一个系统调用服务接口api:/xxx/create?aName=&time=&...,数据没有保存成功提示SQL state [HY000]; error code ...

  3. MySQL 报错:Translating SQLException with SQL state '42000', error code '1064', message

    MySQL报错详细日志 2019-09-12 16:42:29 [http-nio-80-exec-25] DEBUG [org.springframework.jdbc.support.SQLErr ...

  4. nested exception is java.sql.SQLException: Incorrect string value: '\xE7\x99\xBB\xE9\x99\x86...' for column 'image' at row 1

    HTTP Status 500 - Hibernate operation: could not insert: [cn.itcast.shop.product.vo.Product]; uncate ...

  5. 2016.11.10 Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver

    运行项目rds_web时,出现错误提示:Could not get JDBC Connection; nested exception is java.sql.SQLException: No sui ...

  6. Could not get JDBC Connection; nested exception is java.sql.SQLException: ${jdbc.driver}

    在一个SSM分布式项目中一个服务报错: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnec ...

  7. 启动Spring boot报错:nested exception is java.sql.SQLException: Field 'id' doesn't have a default value

    先看具体日志: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with n ...

  8. nested exception is java.sql.SQLException: IO 错误

    1.错误描述 (mx.messaging.messages::ErrorMessage)#0 body = (null) clientId = "18CE3B03-9709-9DA8-763 ...

  9. Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework

    昨晚在 使用spring aop, 然后Tomcat启动的时候, 报了这么个错: Caused by: org.springframework.beans.factory.BeanCreationEx ...

随机推荐

  1. PHP5接口技术入门

    在PHP中我们声明类一般都用class来声明. <?php class Student{ //用class声明一个Student类 function __construct(){ //实例化类的 ...

  2. Android获取当前时间的3中方法总结

    今天听了一在线公开课,任务是做一个数字时钟,其中最关键的自然是获取当前的系统时间.做个简单的记录,如下: 1. Time time = new Time("GMT+8"); tim ...

  3. springMVC是如何实现参数封装和自动返回Json的

    HTTP 请求和响应是基于文本的,意味着浏览器和服务器通过交换原始文本进行通信.但是,使用 Spring,controller 类中的方法返回纯 ‘String’ 类型和域模型(或其他 Java 内建 ...

  4. 使用pyinstaller打包.py程序

    使用pyinstaller打包.py程序 例如打包D:/Desktop 目录下的 filename.py 文件 打开 cmd 将目录切换至 D:/Desktop 输入命令 pyinstaller -F ...

  5. python 基础之集合

    集合 s=set('chen xi') s1=['cx','ee','cx'] s2=set(s1)#set为集合 print(s2,type(s2)) s=list(s2) print(s,type ...

  6. VM安装linux操作系统详细教程

    1.首先我们新建一个虚拟机,先不安装操作系统,稍后再对其安装Linux系统. 新建虚拟机步骤如下: 打开VMware软件,菜单栏点击“文件(F)”–>选择“新建虚拟机(N)”,如下图1,(或者直 ...

  7. Windows驱动开发-IRP的完成例程

    <Windows驱动开发技术详解 >331页, 在将IRP发送给底层驱动或其他驱动之前,可以对IRP设置一个完成例程,一旦底层驱动将IRP完成后,IRP完成例程立刻被处罚,通过设置完成例程 ...

  8. SpringCloud入门——(1)创建Eureka项目

    Eureka是Spring Cloud Netflix微服务套件中的一部分,可以与Springboot构建的微服务很容易的整合起来.Eureka包含了服务器端和客户端组件.服务器端,也被称作是服务注册 ...

  9. Codeforces Round #551 (Div. 2)D(树形DP)

    #define HAVE_STRUCT_TIMESPEC#include <bits/stdc++.h>using namespace std;int val[300007],num[30 ...

  10. 学习不一样的vue4:mock与axios实战1

    学习不一样的vue4:mock与axios实战1  发表于 2017-06-14 |  分类于 web前端|  |  阅读次数 8180 首先 首发博客: 我的博客 项目源码: 源码(喜欢请star) ...