- 浏览: 1884812 次
- 性别:
- 来自: 合肥
文章分类
- 全部博客 (514)
- OPEN (41)
- WARN (33)
- EXPER (16)
- RESOURCE (7)
- TOOL (4)
- DWR (10)
- Struts1.x (10)
- Ibtais (18)
- MyEclipse (30)
- Sql Server (64)
- Tomcat (7)
- APACHE (4)
- JSP (18)
- SERVLET (6)
- ENGLISH (0)
- ECSide (8)
- JasperReports (7)
- JAVA (24)
- JS (42)
- XML (26)
- CVS (8)
- Mind (1)
- JQUERY (2)
- IBATIS (6)
- PROJECT (0)
- STRUTS2 (0)
- PROXOOL (0)
- SPRING (4)
- Hibernate (0)
- SSI (0)
- JBPM (11)
- FLEX (3)
- JSON (2)
- GWT (1)
- jeecms v3 (1)
- Flash (2)
- DATA (1)
- ORACLE (3)
- 查询oracle 中逗号分隔字符串中所有值 (1)
最新评论
-
小小西芹菜:
GoEasy web三步轻松实现web实时推送1. 引入goe ...
服务器推送技术 java -
kg_1997:
这个方法太棒了,可以不用to_date函数,实在是棒!!!
java/oracle日期处理 -
wodesunday:
:idea:
SQL的分段统计查询语句 -
wodesunday:
引用
SQL的分段统计查询语句 -
BlueSkator:
讲的有点浅,没有深入进去
tomcat需要的重新发布和重启服务器的几种情况
Inserting CLOB Values with setCharacterStream() Method
- 博客分类:
- Sql Server
If you want to insert the entire content of a text file into a CLOB column, you should create a Reader object from this file, and use the PreparedStatement.setCharacterStream() method to pass the text file content to the CLOB column through the Reader object. There are 3 versions of the setCharacterStream() method, two of them were added as part of JDBC 4.0 (Java 1.6). Your JDBC driver may not support them:
setCharacterStream(int parameterIndex, Reader reader) - The data will be read from the Reader stream as needed until end-of-file is reached. This was added in JDBC 4.0 (Java 1.6).
setCharacterStream(int parameterIndex, Reader reader, int length) - The data will be read from the Reader stream as needed for "length" characters.
setCharacterStream(int parameterIndex, Reader reader, long length) - The data will be read from the Reader stream as needed for "length" characters. This was added in JDBC 4.0 (Java 1.6).
To test those setCharacterStream() methods, wrote the following program:
C:\>java -cp .;\local\lib\sqljdbc.jar SqlServerClobSetCharacterStream
Exception in thread "main" java.lang.AbstractMethodError: com
.microsoft.sqlserver.jdbc.SQLServerPreparedStatement
.setCharacterStream(ILjava/io/Reader;)V
at SqlServerClobSetCharacterStream.main(SqlServerClobSet...java:34)
"Test 2" also failed for the same reason - fileIn.length() returns "long" and that setCharacterStream(int, Reader, long) is JDBC 4.0 method:
C:\>java -cp .;\local\lib\sqljdbc.jar SqlServerClobSetCharacterStream
Exception in thread "main" java.lang.AbstractMethodError: com
.microsoft.sqlserver.jdbc.SQLServerPreparedStatement
.setCharacterStream(ILjava/io/Reader;J)V
at SqlServerClobSetCharacterStream.main(SqlServerClobSet...java:38)
setCharacterStream(int parameterIndex, Reader reader) - The data will be read from the Reader stream as needed until end-of-file is reached. This was added in JDBC 4.0 (Java 1.6).
setCharacterStream(int parameterIndex, Reader reader, int length) - The data will be read from the Reader stream as needed for "length" characters.
setCharacterStream(int parameterIndex, Reader reader, long length) - The data will be read from the Reader stream as needed for "length" characters. This was added in JDBC 4.0 (Java 1.6).
To test those setCharacterStream() methods, wrote the following program:
/** * SqlServerClobSetCharacterStream.java * Copyright (c) 2007 by Dr. Herong Yang. All rights reserved. */ import java.io.*; import java.sql.*; public class SqlServerClobSetCharacterStream { public static void main(String [] args) { Connection con = null; try { com.microsoft.sqlserver.jdbc.SQLServerDataSource ds = new com.microsoft.sqlserver.jdbc.SQLServerDataSource(); ds.setServerName("localhost"); ds.setPortNumber(1269); ds.setDatabaseName("AdventureWorksLT"); ds.setUser("Herong"); ds.setPassword("TopSecret"); con = ds.getConnection(); // Deleting the record for re-testing String subject = "Test of setCharacterStream() methods"; Statement sta = con.createStatement(); sta.executeUpdate("DELETE FROM Article WHERE Subject = '" +subject+"'"); // Inserting CLOB value with a PreparedStatement PreparedStatement ps = con.prepareStatement( "INSERT INTO Article (Subject, Body) VALUES (?,?)"); ps.setString(1, subject); Reader bodyIn = new FileReader("SqlServerClobSetCharacterStream.java"); // Test 1 - This will not work with JDBC 3.0 drivers // ps.setCharacterStream(2, bodyIn); // Test 2 - This will not work with JDBC 3.0 drivers // File fileIn = new File("SqlServerClobSetCharacterStream.java"); // ps.setCharacterStream(2, bodyIn, fileIn.length()); // Test 3 - This works with JDBC 3.0 drivers File fileIn = new File("SqlServerClobSetCharacterStream.java"); ps.setCharacterStream(2, bodyIn, (int) fileIn.length()); int count = ps.executeUpdate(); bodyIn.close(); ps.close(); // Retrieving CLOB value with getString() sta = con.createStatement(); ResultSet res = sta.executeQuery("SELECT * FROM Article" +" WHERE Subject = '"+subject+"'"); res.next(); System.out.println("The inserted record: "); System.out.println(" Subject = "+res.getString("Subject")); System.out.println(" Body = " +res.getString("Body").substring(0,256)); res.close(); sta.close(); con.close(); } catch (Exception e) { System.err.println("Exception: "+e.getMessage()); e.printStackTrace(); } } }As I mentioned above setCharacterStream(int parameterIndex, Reader reader) will not work with JDBC 3.0 drivers. Here is what I got with the "Test 1" section open in my program. Remember that SQL Server JDBC driver 1.0 is a JDBC 3.0 driver.
C:\>java -cp .;\local\lib\sqljdbc.jar SqlServerClobSetCharacterStream
Exception in thread "main" java.lang.AbstractMethodError: com
.microsoft.sqlserver.jdbc.SQLServerPreparedStatement
.setCharacterStream(ILjava/io/Reader;)V
at SqlServerClobSetCharacterStream.main(SqlServerClobSet...java:34)
"Test 2" also failed for the same reason - fileIn.length() returns "long" and that setCharacterStream(int, Reader, long) is JDBC 4.0 method:
C:\>java -cp .;\local\lib\sqljdbc.jar SqlServerClobSetCharacterStream
Exception in thread "main" java.lang.AbstractMethodError: com
.microsoft.sqlserver.jdbc.SQLServerPreparedStatement
.setCharacterStream(ILjava/io/Reader;J)V
at SqlServerClobSetCharacterStream.main(SqlServerClobSet...java:38)
发表评论
-
ORACLE中使用递归查询 (
2012-12-27 16:35 987在数据库查询中常常会碰到要查询树形结构的数据,需要用一个字段的 ... -
函数与存储过程区别
2011-06-01 18:17 1324本质上没区别。只是 ... -
SQL Server2000安装常见问题
2011-05-25 14:15 1498一:解决安装sql时文件挂起的问题: (1)、点击“开始》运 ... -
MySQL语句优化的原则
2011-04-12 14:21 10041、使用索引来更快 ... -
转SQL-group by学习
2011-04-12 14:18 1277在select 语句中可以使用group by 子句将行划分成 ... -
SQL Select语句完整的执行顺序:
2011-04-12 14:15 1406SQL Select语句完整的执行顺序: 1、from子句组 ... -
SQL截取字符串(substring与patindex的使用)
2011-03-31 13:55 5717SQL截取字符串(substring与patinde ... -
SQL Server2005杂谈(1):使用公用表表达式(CTE)简化嵌套SQL
2011-03-16 09:21 1321先看下面一个嵌套的查 ... -
SQL CHARINDEX (Transact-SQL)
2010-12-06 09:05 1488返回字符串中指定表达式的开始位置。 Transact-SQ ... -
SQL Server基本函数
2010-12-06 08:53 1618SQL Server基本函数 1.字符串函数 : ... -
SQL2005级联删除,层叠,设置空,设置默认值
2010-12-01 15:46 2453浅谈SQL SERVER 2005 之引用 ... -
sql 显示插入主键
2010-10-22 16:28 1311set identity_insert [T_ADMINTYP ... -
取小数
2010-10-22 16:12 1310使用这个方式来计算 SELECT convert(decima ... -
oracle 创建表空间
2010-10-12 11:28 1539一.创建表空间 CREATE SMALLFILE TABLES ... -
sql 约束大全
2010-09-27 16:28 1370--------添加主键约束(bookid作为主键) alt ... -
sql 主外键语法
2010-09-27 08:39 1745alter table dbo.t_commAtta ... -
在SQL Server中,关于with as使用介绍
2010-09-26 13:32 36098一.WITH AS的含义 ... -
procedure 存储过程多个返回测试
2010-09-01 10:26 1194create procedure test(@temp1 va ... -
sql 实现按月份,季度统计报表
2010-08-30 12:01 14980呵呵,我们在处理设计到日期统计时候经常会按照年度,季度,月份统 ... -
SQL Server DATEPART() 不能言
2010-08-30 11:29 1833今天做按月份,按年度,按季度统计报表,后来发现了最简单最可扩展 ...
相关推荐
在这个"Drag and Drop Inserting Text to Input Textbox with jQuery"的项目中,我们关注的是如何利用jQuery库来实现这一功能,特别是在输入文本框中插入拖放文本的场景。jQuery是一个流行的JavaScript库,它简化了...
- ADD: Add TFlexPanel.InvalidateControl virtual method which calls from TFlexControl.Invalidate and can be overriden (it is possible now to catch all object invalidation calls). - FIX: The TFlexPanel....
Readers will learn about SQL operations like selecting, inserting, updating and deleting data using various data types like text, numerical types, images and even audio/video data. After working ...
Bug with inserting identity fields through TUniLoader in the Direct mode is fixed Bug with updating a field containing a space in an alias in the Direct mode is fixed Bug with setting FilterSQL to SQL...
Bug with inserting identity fields through TUniLoader in the Direct mode is fixed Bug with updating a field containing a space in an alias in the Direct mode is fixed Bug with setting FilterSQL to SQL...
Bug with inserting identity fields through TUniLoader in the Direct mode is fixed Bug with updating a field containing a space in an alias in the Direct mode is fixed Bug with setting FilterSQL to SQL...
Bug with inserting identity fields through TUniLoader in the Direct mode is fixed Bug with updating a field containing a space in an alias in the Direct mode is fixed Bug with setting FilterSQL to SQL...
CPU: _System_for_inserting_instruction
This method is based on sequentially inserting the constituent links to the network and simultaneously keeping track of the emerging community structure. Unlike existing algorithms, the SCP method ...
Modern Data Access with Entity Framework Core: Database Programming Techniques for .NET, .NET Core, UWP, and Xamarin with C# By 作者: Holger Schwichtenberg ISBN-10 书号: 1484235517 ISBN-13 书号: ...
Fixed : Issue with default values for ArrowHeight and ArrowWidth in TTMSFMXPopup Fixed : Issue with focusing calendar in TTMSFMXCalendar Fixed : Issue with lookuplist in TTMSFMXEdit in XE3 Fixed :...
print(f"Records inserted with IDs: {results.inserted_ids}") ``` 在上述代码中,我们一次性插入了两个用户记录,并打印出所有新插入文档的ID。 除了基本的插入操作,Python的`pymongo`库还提供了丰富的功能,如...
ApiHooks allows inserting module (with hooks) into the specified process. ApiHooks exports EstablishApiHooks functions for usage in your programs. What is it good for? -------------------- File ...
may be the preferred method. There are lowlevel debuggers that allow you to step through the executable program, instruction by instruction, displaying registers and memory contents in binary.
这篇教程“iPhone Coding Tutorial – Inserting A UITextField In A UIAlertViewController”将会教你如何在现代iOS环境中,在警告视图控制器中添加一个文本字段。 首先,我们需要了解`UIAlertController`的基本...
On most modern ATMs, the customer is identified by inserting a plastic ATM card with a magnetic stripe or a plastic smartcard with a chip, that contains a unique card number and some security ...