当前位置: 技术问答>java相关
急死了! oracle中long数据类型问题! 重酬!!!
来源: 互联网 发布时间:2015-04-07
本文导语: long在oracle文档中是2G的大字符 为什么只能写进3K到4K的字符呢? 再多就会出现 "ORA-01704: 文字字符串过长" 我用的是oracle8.05 | 你的程序是怎么写的?必须要用PreparedStatement以流的方式插入才行 | ...
long在oracle文档中是2G的大字符
为什么只能写进3K到4K的字符呢?
再多就会出现 "ORA-01704: 文字字符串过长"
我用的是oracle8.05
为什么只能写进3K到4K的字符呢?
再多就会出现 "ORA-01704: 文字字符串过长"
我用的是oracle8.05
|
你的程序是怎么写的?必须要用PreparedStatement以流的方式插入才行
|
LONG, RAW, LONG RAW, VARCHAR2
You can use the piecewise capabilities provided by OCIBindByName(), OCIBindByPos(), OCIDefineByPos(), OCIStmtGetPieceInfo() and OCIStmtSetPieceInfo() to perform inserts, updates or fetches involving column data of these types.
你用OCI的话可以用上面的Bind的方法,
你用jdbc则要用流来输入。
下面JDBC用文件流读写LONG字段的例子:
/*
* This example shows how to stream data from the database
*/
import java.sql.*;
import java.io.*;
class StreamExample
{
public static void main (String args [])
throws SQLException, IOException
{
// Load the driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger");
// It's faster when you don't commit automatically
conn.setAutoCommit (false);
// Create a Statement
Statement stmt = conn.createStatement ();
// Create the example table
try
{
stmt.execute ("drop table streamexample");
}
catch (SQLException e)
{
// An exception would be raised if the table did not exist
// We just ignore it
}
// Create the table
stmt.execute ("create table streamexample (NAME varchar2 (256), DATA long)");
// Let's insert some data into it. We'll put the source code
// for this very test in the database.
File file = new File ("StreamExample.java");
InputStream is = new FileInputStream ("StreamExample.java");
PreparedStatement pstmt =
conn.prepareStatement ("insert into streamexample (data, name) values (?, ?)");
pstmt.setAsciiStream (1, is, (int)file.length ());
pstmt.setString (2, "StreamExample");
pstmt.execute ();
// Do a query to get the row with NAME 'StreamExample'
ResultSet rset =
stmt.executeQuery ("select DATA from streamexample where NAME='StreamExample'");
// Get the first row
if (rset.next ())
{
// Get the data as a Stream from Oracle to the client
InputStream gif_data = rset.getAsciiStream (1);
// Open a file to store the gif data
FileOutputStream os = new FileOutputStream ("example.out");
// Loop, reading from the gif stream and writing to the file
int c;
while ((c = gif_data.read ()) != -1)
os.write (c);
// Close the file
os.close ();
}
// Close all the resources
if (rset != null)
rset.close();
if (stmt != null)
stmt.close();
if (pstmt != null)
pstmt.close();
if (conn != null)
conn.close();
}
}
You can use the piecewise capabilities provided by OCIBindByName(), OCIBindByPos(), OCIDefineByPos(), OCIStmtGetPieceInfo() and OCIStmtSetPieceInfo() to perform inserts, updates or fetches involving column data of these types.
你用OCI的话可以用上面的Bind的方法,
你用jdbc则要用流来输入。
下面JDBC用文件流读写LONG字段的例子:
/*
* This example shows how to stream data from the database
*/
import java.sql.*;
import java.io.*;
class StreamExample
{
public static void main (String args [])
throws SQLException, IOException
{
// Load the driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger");
// It's faster when you don't commit automatically
conn.setAutoCommit (false);
// Create a Statement
Statement stmt = conn.createStatement ();
// Create the example table
try
{
stmt.execute ("drop table streamexample");
}
catch (SQLException e)
{
// An exception would be raised if the table did not exist
// We just ignore it
}
// Create the table
stmt.execute ("create table streamexample (NAME varchar2 (256), DATA long)");
// Let's insert some data into it. We'll put the source code
// for this very test in the database.
File file = new File ("StreamExample.java");
InputStream is = new FileInputStream ("StreamExample.java");
PreparedStatement pstmt =
conn.prepareStatement ("insert into streamexample (data, name) values (?, ?)");
pstmt.setAsciiStream (1, is, (int)file.length ());
pstmt.setString (2, "StreamExample");
pstmt.execute ();
// Do a query to get the row with NAME 'StreamExample'
ResultSet rset =
stmt.executeQuery ("select DATA from streamexample where NAME='StreamExample'");
// Get the first row
if (rset.next ())
{
// Get the data as a Stream from Oracle to the client
InputStream gif_data = rset.getAsciiStream (1);
// Open a file to store the gif data
FileOutputStream os = new FileOutputStream ("example.out");
// Loop, reading from the gif stream and writing to the file
int c;
while ((c = gif_data.read ()) != -1)
os.write (c);
// Close the file
os.close ();
}
// Close all the resources
if (rset != null)
rset.close();
if (stmt != null)
stmt.close();
if (pstmt != null)
pstmt.close();
if (conn != null)
conn.close();
}
}
|
猪肉伦你个问题不是说换了driver就行了吗??