在网上查找了相关资料,有这样一个思路:通过Sql Server提供的ReadText进行分段读取,然后把ReadText放进存储过程,Java来调用存储过程获得读取字符串的指针,但问题是Java获得指针后,如何获得具体的字符串的内容呢?具体步骤如下:
1、创建表
CREATE TABLE yb_table_oa
(
id int,
content text
)
2、创建存储过程
CREATE PROCEDURE dbo.getText
@readt varbinary(16) output
AS
declare @ptr binary(16)
select @ptr=textptr(content)
from yb_table_oa
where id=1
readtext yb_table_oa.content @ptr 0 1000
set @readt=@ptr
return 1234
GO
3、调用的Java代码
public String callTextString(String artId) {
String textStr = "";
if (StringFun.notNull(artId)) {
Connection conn=null;
CallableStatement proc = null;
try
{
//建立连接
conn = SQLConnectionManager.getInstance().getSQLConnection();
defaultCommit = conn.getAutoCommit();
proc = conn.prepareCall("{?=call getText(?)}");
proc.registerOutParameter(1,Types.INTEGER);
proc.registerOutParameter(2,Types.VARBINARY);
proc.execute();
byte[] ptr = proc.getBytes(1);
//关键这里获得指针后如何读取到字符串的内容呢?
proc.close();
conn.close();
}
catch(Exception ex)
{
SystemLogger.instance().logError(ex.getMessage()); }
}
return textStr;
} 或者各位前辈和大侠有更好的方法,请告知,先行谢过了!
1、创建表
CREATE TABLE yb_table_oa
(
id int,
content text
)
2、创建存储过程
CREATE PROCEDURE dbo.getText
@readt varbinary(16) output
AS
declare @ptr binary(16)
select @ptr=textptr(content)
from yb_table_oa
where id=1
readtext yb_table_oa.content @ptr 0 1000
set @readt=@ptr
return 1234
GO
3、调用的Java代码
public String callTextString(String artId) {
String textStr = "";
if (StringFun.notNull(artId)) {
Connection conn=null;
CallableStatement proc = null;
try
{
//建立连接
conn = SQLConnectionManager.getInstance().getSQLConnection();
defaultCommit = conn.getAutoCommit();
proc = conn.prepareCall("{?=call getText(?)}");
proc.registerOutParameter(1,Types.INTEGER);
proc.registerOutParameter(2,Types.VARBINARY);
proc.execute();
byte[] ptr = proc.getBytes(1);
//关键这里获得指针后如何读取到字符串的内容呢?
proc.close();
conn.close();
}
catch(Exception ex)
{
SystemLogger.instance().logError(ex.getMessage()); }
}
return textStr;
} 或者各位前辈和大侠有更好的方法,请告知,先行谢过了!
解决方案 »
- 字符串问题
- java编译时警告:编码GBK的不可映射字符,怎么解决呢?
- 求按空格,逗号,中文逗号分隔的正则表达式
- JFrame 修改标题栏颜色??
- 一个困惑已久的问题,关于变量的更新,大家怎么解决的?
- 我想问一个布局(容器问题),大家帮我看看!!
- 帮帮忙!关于URLConnection的保留session进行程序定向问题!
- 用java开发数据库,连接db2应该如何设置classpath (或者说应引入哪个包)
- W2000下,websphere3.0可不可以用啊,数据库是DB27。1
- JDBC 执行 Insert Select 联合语句.
- 字符串“254”如何转换为16进制的“FE”
- 求助:J2SE
select id,name,content from info,假如content是Text类型的字段,你在java中读取的顺序必须是:
rs.getInt("id");
rs.getString("name");
rs.getString("content");
这个用微软的JDBC取得程序有关!