- 浏览: 196628 次
- 性别:
- 来自: 芜湖
文章分类
- 全部博客 (139)
- 软件 (0)
- Pattern (6)
- CSDN导入 (19)
- Struts (3)
- [网站分类]1.网站首页原创 (27)
- [网站分类]6.转载区 (4)
- Hibernate (10)
- Error (8)
- [网站分类]2.Java新手区 (20)
- Java (8)
- [网站分类]4.其他技术区 (10)
- Web (1)
- C++ (2)
- Algorithm (4)
- Linux (2)
- Skill (1)
- Tech (2)
- Note (2)
- [网站分类]3.非技术区 (1)
- Database (1)
- Winty (7)
- [网站分类]1.网站首页原创Java技术区(对首页文章的要求: 原创、高质量、经过认真思考并精心写作。BlogJava管理团队会对首页的文章进行管理。) (0)
最新评论
-
haohao-xuexi02:
很不错哦。
O'Reilly cos上传组件的使用(1/3) - 上传文件 -
yoin528:
useUnicode=true&charact ...
[原]向MySQL数据库插入Blob数据的问题 -
xiaoqing20:
下载来看看!呵呵
[原]Struts2类型转换 -
xiaoqing20:
[原]Struts2类型转换
[标题]:向MySQL数据库插入Blob数据的问题
[时间]:2009-6-3
[摘要]:在使用Hibernate向数据库插入Blob二进制数据时,发生如下错误:SQL Error: 1064, SQLState: 42000 。You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??^5b??08""199G?"0Px8=?ü??Y??ó??l%P?[
¨???ó`-??F????:???S?a?@??Zu??' at line 1
[关键字]:MySQL、Blob、图片、image、java、Hibernate、Clob、&
[环境]:5.1.34-community MySQL Community Server (GPL),Hibernate 3.2.5
[作者]:Winty (wintys@gmail.com) http://www.blogjava.net/wintys
[错误]:
使用Hibernate向数据库插入Blob二进制数据,程序如下:
[原因]:
搜索了一下,错误原因可能为:"在定义字段时,不要和MYSQL的保留字段有相同的"。
检查了一下表中的字段名,没有发现问题:
如果把Blob相关的程序注释了,Clob数据能够正常写入。原因当然出在Blob数据的写入程序中。后来发现,把Blob写入的图片数据换成文本,却可以正常写入。可见,是二进制数据的编码问题。
[解决]:
将原来的数据连接:
Error parsing XML: /hibernate.cfg.xml(12) The reference to entity "characterEncoding" must end with the ';' delimiter.
也可以直接把&修改为&
即:
jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf-8
[参考资料]:
Mysql 中的blob相关问题 : http://fenghuang.iteye.com/blog/363931
[时间]:2009-6-3
[摘要]:在使用Hibernate向数据库插入Blob二进制数据时,发生如下错误:SQL Error: 1064, SQLState: 42000 。You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??^5b??08""199G?"0Px8=?ü??Y??ó??l%P?[
¨???ó`-??F????:???S?a?@??Zu??' at line 1
[关键字]:MySQL、Blob、图片、image、java、Hibernate、Clob、&
[环境]:5.1.34-community MySQL Community Server (GPL),Hibernate 3.2.5
[作者]:Winty (wintys@gmail.com) http://www.blogjava.net/wintys
[错误]:
使用Hibernate向数据库插入Blob二进制数据,程序如下:
public void insert() {
User user = new User();
Transaction tc = null;
try{
Session session = HibernateUtil.getSession();
tc = session.beginTransaction();
user.setName("The Name");
FileInputStream fin = new FileInputStream("rc/redheart.gif");
Blob image = Hibernate.createBlob(fin);
user.setImage(image);
File file = new File("rc/news.txt");
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
Clob info = Hibernate.createClob(br , (int)file.length());
user.setInfo(info);
session.save(user);
tc.commit();
}catch(Exception e){
if(tc != null){
tc.rollback();
}
System.err.println(e.getMessage());
}finally{
HibernateUtil.closeSession();
}
}
发生如下错误:User user = new User();
Transaction tc = null;
try{
Session session = HibernateUtil.getSession();
tc = session.beginTransaction();
user.setName("The Name");
FileInputStream fin = new FileInputStream("rc/redheart.gif");
Blob image = Hibernate.createBlob(fin);
user.setImage(image);
File file = new File("rc/news.txt");
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
Clob info = Hibernate.createClob(br , (int)file.length());
user.setInfo(info);
session.save(user);
tc.commit();
}catch(Exception e){
if(tc != null){
tc.rollback();
}
System.err.println(e.getMessage());
}finally{
HibernateUtil.closeSession();
}
}
Hibernate: insert into db.myblobclob (name, image, info, id) values (?, ?, ?, ?)
00:33:45,671 WARN JDBCExceptionReporter:77 - SQL Error: 1064, SQLState: 42000
00:33:45,671 ERROR JDBCExceptionReporter:78 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??^5b??08""199G?"0Px8=?ü??Y??ó??l%P?[
¨???ó`-??F????:???S?a?@??Zu??' at line 1
00:33:45,687 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at wintys.hibernate.blobclob.UserDAOBean.insert(UserDAOBean.java:41)
at wintys.hibernate.blobclob.UserTest.main(UserTest.java:18)
Caused by: java.sql.BatchUpdateException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??^5b??08""199G?"0Px8=?ü??Y??ó??l%P?[
¨???ó`-??F????:???S?a?@??Zu??' at line 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1693)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1108)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 9 more
Could not execute JDBC batch update
Hibernate: select user0_.id as id0_, user0_.name as name0_, user0_.image as image0_, user0_.info as info0_ from db.myblobclob user0_
00:33:45,671 WARN JDBCExceptionReporter:77 - SQL Error: 1064, SQLState: 42000
00:33:45,671 ERROR JDBCExceptionReporter:78 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??^5b??08""199G?"0Px8=?ü??Y??ó??l%P?[
¨???ó`-??F????:???S?a?@??Zu??' at line 1
00:33:45,687 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at wintys.hibernate.blobclob.UserDAOBean.insert(UserDAOBean.java:41)
at wintys.hibernate.blobclob.UserTest.main(UserTest.java:18)
Caused by: java.sql.BatchUpdateException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??^5b??08""199G?"0Px8=?ü??Y??ó??l%P?[
¨???ó`-??F????:???S?a?@??Zu??' at line 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1693)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1108)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 9 more
Could not execute JDBC batch update
Hibernate: select user0_.id as id0_, user0_.name as name0_, user0_.image as image0_, user0_.info as info0_ from db.myblobclob user0_
[原因]:
搜索了一下,错误原因可能为:"在定义字段时,不要和MYSQL的保留字段有相同的"。
检查了一下表中的字段名,没有发现问题:
CREATE TABLE myblobclob(
id VARCHAR(100) NOT NULL,
name VARCHAR(100),
image BLOB,
info TEXT,
PRIMARY KEY(id)
);
id VARCHAR(100) NOT NULL,
name VARCHAR(100),
image BLOB,
info TEXT,
PRIMARY KEY(id)
);
如果把Blob相关的程序注释了,Clob数据能够正常写入。原因当然出在Blob数据的写入程序中。后来发现,把Blob写入的图片数据换成文本,却可以正常写入。可见,是二进制数据的编码问题。
[解决]:
将原来的数据连接:
<property name="connection.url">
jdbc:mysql://localhost:3306/db
</property>
修改成:jdbc:mysql://localhost:3306/db
</property>
<property name="connection.url">
<![CDATA[jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf-8]]>
</property>
注意,在将连接字符串放到CDATA中,因为&是XML中的转义字符。不然会提示错误:<![CDATA[jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf-8]]>
</property>
Error parsing XML: /hibernate.cfg.xml(12) The reference to entity "characterEncoding" must end with the ';' delimiter.
也可以直接把&修改为&
即:
jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=utf-8
[参考资料]:
Mysql 中的blob相关问题 : http://fenghuang.iteye.com/blog/363931
发表评论
-
[原]MyEclipse location already exists
2009-07-27 00:37 1700[标题]:[原]MyEclipse location alre ... -
[原]Exception starting filter MyStruts2
2009-07-27 19:41 1013[标题]:[原]Exception starting filt ... -
[原]Struts2校验框架
2009-07-27 23:54 1083[标题]:[原]Struts2校验框架 [时间]:2009- ... -
[原]Struts2-拦截器
2009-08-01 00:21 1126[标题]:[原]Struts2-拦截器 [时间]:2009- ... -
[原]Struts2-文件上传与下载
2009-08-08 08:48 2145[标题]:[原]Struts2-文件上 ... -
[原]Struts2-国际化
2009-08-10 18:13 1869[标题]:[原]Struts2-国际化 [时间]:2009- ... -
[原]Struts2-深入探索
2009-08-29 20:32 1031[标题]:[原]Struts2-深入探索 [时间]:2009 ... -
[原]Struts2-整合JFreeChart
2009-09-03 17:10 1880[标题]:[原]Struts2-整合JFr ... -
[转]Java 小例子:数据持久化(保存数据到文件)
2009-03-16 11:00 1745说数据持久化,初学者可能还不太懂;但要说把数据保存到文件,这谁 ... -
[原]调试EL函数时,Tomcat提示NullPointerException
2009-04-03 19:02 892[标题]:调试EL函数时,Tomcat提示NullPointe ... -
[原]HelloWorldServlet
2009-05-27 22:16 904编译运行步骤: 1、将HelloWorldServlet.ja ... -
[原]getServletInfo()
2009-05-27 23:16 1345《JSP完全学习手册》学习心得之:getServletInfo ... -
[原]jsp:forward
2009-05-27 23:24 886《JSP完全学习手册》学习心得:jsp:forward Jud ... -
[原]jsp:param
2009-05-27 23:27 1544《JSP完全学习手册》学习心得:jsp:param param ... -
[原]request.getParameterValues()
2009-05-27 23:32 1185《JSP完全学习手册》学习心得:request.getPara ... -
[原]隐含对象config
2009-05-27 23:54 721《JSP完全学习手册》学习心得:隐含对象config < ... -
[原]cookie读写
2009-05-28 00:03 831《JSP完全学习手册》学习心得:cookie读写 <%@ ... -
[原]getHttpHeader
2009-05-28 00:14 818《JSP完全学习手册》学习心得:getHttpHeader g ... -
[原]SQL内外连接
2009-06-17 22:31 891-- Author:Winty(天堂露珠) -- Date: ...
相关推荐
向数据库插入blob数据实例源码.rar 在mysql中通过。
向数据库插入blob数据实例源码--在mysql和oracle中通过.rar
mysql导出工具,可导出无注释插入语句,表中字段有blob类数据,插入语句前还有锁表操作语句,适合多种场景
spring 中对大数据的处理,包括clob,blob的数据。比之jdbc下简便很多。
从oracle中的BLOB类型字段中取出照片,转存到mysql数据库中。思路是现将oracle中的照片存储在本地文件夹,在将本地图片上传到mysql中。
Java中 Blob的插入与读取
在使用mysql的过程中,有个问题就是mysql的优化,mysql中longblob字段在5.5版本中默认的为1M。 想改变这个问题,需要注意几点: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (2054817 > ...
MYBLOB_DEMO - 演示 MYBLOB 工具包的使用MYBLOB_OPEN - 打开与 MySQL 数据库的连接MYBLOB_COMMAND - 将 SQL 语句发送到 MySQL 数据库MYBLOB_FROM_DB - 从 MySQL 数据库中检索 blob(二进制大对象) MYBLOB_TO_DB - ...
Mybatis 处理 CLOB、BLOB 类型数据
Data row to insert sql是一个小的工具软件,可以将数据库表中指定数据转换成相应的insert sql语句。目前支持的数据库类型为oracle,db2,ms sql server。 目前还有一些缺陷,还有待完善,具体如下: 1、对ms sql ...
# MySQL每打开一个表,都会读入一些数据到table_open_cache缓存中,当MySQL在这个缓存中找不到相应信息时,才会去磁盘上读取。默认值64 # 假定系统有200个并发连接,则需将此参数设置为200*N(N为每个连接所需的文件...
MySQL中外键的table的外键引用列可以插入数据可以为null,不参照主表的数据。 使用子查询插入数据 insert into temp(name) select name from classes; 多行插入 insert into temp values(null, ‘jack’, 22), ...
主要介绍了提高MySQL中InnoDB表BLOB列的存储效率的教程,InnoDB的优化在MySQL的优化研究中也是一个非常热门的课题,需要的朋友可以参考下
进入mysql数据库控制台, 如mysql -u root -p mysql>use 数据库 然后使用source命令,后面参数为脚本文件(如这里用到的.sql) mysql>source wcnc_db.sql B:使用mysqldump命令 mysqldump -u username -p dbname ...
9.4 MySQL数据库表类型 10 从 MySQL 得到最大的性能 10.1 优化概述 10.2 系统/编译时和启动参数的调节 10.2.1 编译和链接如何影响 MySQL 的速度 10.2.2 磁盘问题 10.2.2.1 为数据库和...
15.6 向关联数据表插入新数据记录 15.7 处理来自HTML表单的输入数据 15.8 分页显示查询结果 15.9 处理层次化数据 15.10 速度优化 15.11 Unicode 15.12 二进制数据(BLOB)和图像 15.13 存储...
首先是数据库建立要准备的: 我们要把放置二进制字段设置为Blob类型,根据文件的大小选择合适的Blob类型,一下是各个Blob类型所能容纳二进制文件的大小 MySQL的四种BLOB类型 类型 大小(单位:字节) TinyBlob 最大 ...
Mysql中可以存储大文件数据,一般使用的BLOB对象。如图片,视频等等。 BLOB是一个二进制大对象,可以容纳可变数量的数据。因为是二进制对象,所以与编码方式无关。有4种BLOB类型:TINYBLOB、BLOB、MEDIUMBLOB和...
15.6 向关联数据表插入新数据记录 15.7 处理来自HTML表单的输入数据 15.8 分页显示查询结果 15.9 处理层次化数据 15.10 速度优化 15.11 Unicode 15.12 二进制数据(BLOB)和图像 15.13 存储过程 ...