ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher.Mathru...@sybase.com
Subject RE: Scanning byte array
Date Mon, 02 Oct 2006 23:19:33 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii" plain; text 
Content-Type: 7bit Content-Transfer-Encoding:>
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=829391723-02102006><FONT color=#0000ff

size=2>Again, look at the JavaDocs. You've got a byte[], so to write you could 
use a ByteArrayOutputStream. To read you could use a ByteArrayInputStream. There 
are many other classes in the java.io package that lend themselves to how and 
where you write the data. </FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> soussou97 &lt;dboussebha@yahoo.fr&gt;

[mailto:soussou97 &lt;dboussebha@yahoo.fr&gt;] <BR><B>Sent:</B>
Monday, October 
02, 2006 3:15 PM<BR><B>To:</B> user-java@ibatis.apache.org<BR><B>Subject:</B>

RE: Scanning byte array<BR></FONT><BR></DIV>
<DIV></DIV><BR>Hi Christopher; <BR><BR>OK but I must only read
the byte[] or 
write it also in using <BR>ByteArrayOutputStream or both (read &amp; write) ? 
<BR><BR>Thank's <BR><BR><BR>Christopher.Mathrusse wrote: <BR>&gt;
<BR>&gt; 
<BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt;
Once you have a byte[] you can read 
it using a ByteArrayInputStream and <BR>&gt; you can write it using 
ByteArrayOutputStream. <BR>&gt; You should look at the JavaDocs to learn more 
about these <BR>&gt; classes. <BR>&gt; &nbsp; <BR>&gt; For
reading the 
byte[]&nbsp;you could, for example, do the <BR>&gt; following: <BR>&gt;
&nbsp; 
<BR>&gt; <BR>&gt; java.sql.Connection connection = this.getConnection();

<BR>&gt; java.sql.PreparedStatement statement = <BR>&gt; 
connection.prepareStatement("select data from <BR>&gt; DATASTORE where ID = ?");

<BR>&gt; statement.setObject(1, primaryKey); <BR>&gt; byte[] documentData
= 
null; <BR>&gt; <BR>&gt; java.sql.ResultSet result = statement.executeQuery();

<BR>&gt; if <BR>&gt; (result.next()) { <BR>&gt; documentData
= 
result.getBytes(1); <BR>&gt; } <BR>&gt; <BR>&gt; java.io.ByteArrayInputStream

bis = new <BR>&gt; java.io.ByteArrayInputStream(documentData); <BR>&gt;
<BR>&gt; 
java.io.BufferedReader in <BR>&gt; = new <BR>&gt; java.io.BufferedReader(new

java.io.InputStreamReader(bis)); <BR>&gt; <BR>&gt; String str = null;
<BR>&gt; 
do <BR>&gt; { <BR>&gt; str = in.readLine(); <BR>&gt; // do something
<BR>&gt; 
here <BR>&gt; } while(str != <BR>&gt; null); <BR>&gt; &nbsp;
<BR>&gt; <BR>&gt; 
<BR>&gt; From: soussou97 &lt;dboussebha@yahoo.fr&gt; <BR>&gt;
[mailto:soussou97 
&lt;dboussebha@yahoo.fr&gt;] Sent: Monday, October <BR>&gt; 02, 2006 1:20
AM To: 
user-java@ibatis.apache.org Subject: <BR>&gt; RE: Scanning byte array <BR>&gt;

Hi Christopher ; OK for your example but imagined that <BR>&gt; you do not have

of documents but of data, so firstly to get the data out <BR>&gt; of <BR>&gt;

the table as into the example : connection = this.getConnection(); <BR>&gt; 
statement = connection.prepareStatement("select data from DATASTORE <BR>&gt; 
where ID = ?"); statement.setObject(1, primaryKey); byte[] documentData <BR>&gt;

= null; ResultSet result = statement.executeQuery(); if (result.next()) <BR>&gt;

{ Data = result.getBytes(1); } Next you make how to extract the <BR>&gt; data 
inside of array (which can be : integer, string, etc...) ? <BR>&gt; Regards; 
Christopher.Mathrusse wrote: &gt; &gt; <BR>&gt; &gt; &gt; &gt;
&gt; &gt; When I 
was working with Oracle and <BR>&gt; needed to store XML &gt; documents in the

database I defined the column <BR>&gt; type <BR>&gt; as LONG RAW. Then
I &gt; 
was able &gt; to stream the data into the table <BR>&gt; by using the following:

&gt; &nbsp; &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&gt;
PreparedStatement &gt; 
statement = connection.prepareStatement("insert <BR>&gt; into <BR>&gt;

DOCUMENTSTORE &gt; values(?,?)"); &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<BR>&gt; 
ByteArrayInputStream &gt; stream = new &gt; <BR>&gt; 
ByteArrayInputStream(documentData); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &gt;
<BR>&gt; 
statement.setBinaryStream(1, stream, &gt; documentData.length); &gt; To <BR>&gt;

get the data out of the&nbsp;table I &gt; used the following: &gt; <BR>&gt;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; connection = &gt; this.getConnection();
<BR>&gt; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; statement = &gt; <BR>&gt;

connection.prepareStatement("select DOCUMENT from DOCUMENTSTORE where ID = 
<BR>&gt; &gt; ?"); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; statement.setObject(1,
&gt; 
<BR>&gt; primaryKey); &gt; &nbsp; &gt; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[] <BR>&gt; documentData
&gt; = null; 
&gt; &nbsp; &gt; <BR>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ResultSet result = &gt; 
<BR>&gt; statement.executeQuery(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if &gt; 
<BR>&gt; (result.next()) &gt; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<BR>&gt; documentData = &gt; result.getBytes(1); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<BR>&gt; &gt; } &gt; &nbsp; &gt; &nbsp; &gt; &gt; &gt;
From: <BR>&gt; soussou97 
&lt;dboussebha@yahoo.fr&gt; &gt; [mailto:soussou97 <BR>&gt; 
&lt;dboussebha@yahoo.fr&gt;] Sent: Friday, &gt; September 29, 2006 5:16 AM 
<BR>&gt; To: &gt; user-java@ibatis.apache.org Subject: Scanning byte &gt;
array 
<BR>&gt; &gt; Hi; I have a method which return a byte array from a BLOB &gt;

<BR>&gt; (Oracle) : public static byte[] getBLOB(int id, Connection conn) throws

<BR>&gt; &gt; <BR>&gt; Exception { ResultSet rs = null; PreparedStatement
pstmt 
= null; &gt; <BR>&gt; String <BR>&gt; query = "SELECT data FROM Table1
WHERE id 
= ?"; try { pstmt = &gt; <BR>&gt; conn.prepareStatement(query); pstmt.setInt(1,

id); rs = &gt; <BR>&gt; pstmt.executeQuery(); rs.next(); Blob blob = 
rs.getBlob(1); return &gt; <BR>&gt; blob.getBytes(1, (int) blob.length()); }

finally { rs.close(); &gt; <BR>&gt; pstmt.close(); conn.close(); } } } I must
to 
&gt; scan the byte array <BR>&gt; position by position for extracting of the

data &gt; contained into this <BR>&gt; array for a display in using a GUI. Which

is the best &gt; (performance) <BR>&gt; solution to implemente this ? Regards;

-- &gt; View this message in <BR>&gt; context: <BR>&gt; &gt; 
http://www.nabble.com/Scanning-byte-array-tf2356548.html#a6563833 <BR>&gt; Sent

<BR>&gt; &gt; from &gt; the iBATIS - User - Java mailing list archive at

<BR>&gt; Nabble.com. &gt; &gt; &gt; &gt; -- View this message <BR>&gt;
in 
context: <BR>&gt; 
http://www.nabble.com/Scanning-byte-array-tf2356548.html#a6597501 <BR>&gt; Sent

from the iBATIS - User - Java mailing list archive at Nabble.com. <BR>&gt; 
<BR>&gt; <BR>&gt; <BR>&gt; <BR><BR>-- <BR>View
this message in context: 
http://www.nabble.com/Scanning-byte-array-tf2356548.html#a6610758 <BR>Sent from 
the iBATIS - User - Java mailing list archive at Nabble.com. 
<BR><BR><BR></BODY></HTML>


Mime
View raw message