4. Streams: Long columns in JDBC are streamed. * To set a long (Stream) column pstmt.setAsciiStream (1, <input-stream>, <input-stream-length>); If the string data is in Unicode format, then use setUnicodeStream. pstmt.setUnicodeStream (1, <input-stream>, <input-stream-length>); For long raw columns, use setBinaryStream pstmt.setBinaryStream (1, <input-stream>, <input-stream-length>);
create table streamexample (data long) PreparedStatement pstmt = conn.prepareStatement ("insert into streamexample values (?)"); InputStream is = new FileInputStream ("notes.txt"); File file = new File ("notes.txt"); pstmt.setAsciiStream (1, is, (int)file.length ()); * To retrieve a long column ResultSet rset = stmt.executeQuery ("select * from streamexample");
InputStream ascii_data = rset.getAsciiStream (1); // Loop, reading from the gif stream and writing to the file int c; while ((c = ascii_data.read ()) != -1) Systemm.out.print(c);--------------- [email protected]
是不是输的都是数字。
汗字能用Long来存放吗?
用Varchar2,他是边长的。
肯定够你用。
http://www.csdn.net/expert/topic/689/689587.xml?temp=.2042658
将文本内容保存到数据库中时候,建议你以二进制的形式
保存到数据库中,取得时候再以二进制的方式读出来,
差不多就可以了。如果帖子的内容不超过2000字,则可以使用
varchar2类型保存
尝试以下
在SQL用TEXT字段;我已经实现用JSP读写,如需要可以具体交流!
* To set a long (Stream) column
pstmt.setAsciiStream (1, <input-stream>, <input-stream-length>); If the string data is in Unicode format, then use setUnicodeStream.
pstmt.setUnicodeStream (1, <input-stream>, <input-stream-length>); For long raw columns, use setBinaryStream
pstmt.setBinaryStream (1, <input-stream>, <input-stream-length>);
create table streamexample (data long) PreparedStatement pstmt =
conn.prepareStatement ("insert into streamexample values (?)");
InputStream is = new FileInputStream ("notes.txt");
File file = new File ("notes.txt");
pstmt.setAsciiStream (1, is, (int)file.length ());
* To retrieve a long column
ResultSet rset =
stmt.executeQuery ("select * from streamexample");
InputStream ascii_data = rset.getAsciiStream (1); // Loop, reading from the gif stream and writing to the file
int c;
while ((c = ascii_data.read ()) != -1)
Systemm.out.print(c);---------------
[email protected]