java如何访问Oracle的long类型?

我现在想用一个字段来存长字符串(在于4000,varchar2不能满足),想到用LONG,但是用JDBC连的时报SQL不正确,请高人指点,相当紧急!!!!

 

Do a search with Google... e.g.
Sample demonstrating the usage of LONG type
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/basic/LongSample/Readme.html


// Populate the ResultSet
while(resultSet.next()) {
InputStream insurancedata; // Holds the LONG data
StringBuffer dataBuffer = new StringBuffer();

/* Obtain the LONG data into a byte array. LONG data can be accessed in
two ways: 1) By retrieving all the data in one shot (getBytes method)
2) By using streams. The LONG data is made available to the program
as an Ascii or Unicode stream, and the data can be retrieved chunk by
chunk, which is more eficient in terms of memory usage
In this sample we illustrate retrieval using streams */
insurancedata = resultSet.getAsciiStream(1);
while((chunk = insurancedata.read()) != -1) {
dataBuffer.append((char)chunk);
}

 

 

 

Code for inserting Long Data

public void insertData(String code, String name, String partner, 
String textfile) throws Exception {

// Create a File to read data from the specified text file (textfile)
File file =
new File(getClass().getClassLoader().getResource(textfile).getFile());


// Prepare the statement for inserting a row into the OTN_AIRLINES_LONG
PreparedStatement pstmt = connection.prepareStatement(" INSERT INTO "+
"otn_airlines_long( code, name, partner,"+
"airline_insurance_data) VALUES(?, ?, ?, ?)");


// Bind the parameter values for the above statement
pstmt.setString(1, code);
pstmt.setString(2, name);
pstmt.setString(3, partner);

// Bind the AIRLINE_INSURANCE_DATA column to an input Ascii stream that
// returns the Ascii data to be inserted into the LONGRAW column
pstmt.setCharacterStream(4, new FileReader(file), (int)file.length());


// Execute the statement
pstmt.execute();
}
}
................
................

Code for retrieving Long Data

public void displayLongData(String code) {
........
........
// Create a PreparedStatement object to execute the QUERY
PreparedStatement pst =
connection.prepareStatement("SELECT airline_insurance_data"+
" FROM otn_airlines_long WHERE code = ?");


// Bind the airline code to the query
pst.setString(1, code);

gui.putStatus("Reading Long Column from the DB, Please wait...");

// Excute the Query
ResultSet resultSet = pst.executeQuery();

// Populate the ResultSet
while(resultSet.next()) {
InputStream insurancedata; // Holds the LONG data
StringBuffer dataBuffer = new StringBuffer();

/* Obtain the LONG data into a byte array. LONG data can be accessed in
two ways: 1) By retrieving all the data in one shot (getBytes method)
2) By using streams. The LONG data is made available to the program
as an Ascii or Unicode stream, and the data can be retrieved chunk by
chunk, which is more eficient in terms of memory usage
In this sample we illustrate retrieval using streams */
insurancedata = resultSet.getAsciiStream(1);
while((chunk = insurancedata.read()) != -1) {
dataBuffer.append((char)chunk);
}

................
................

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冷月宫主

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值