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 Fri, 29 Sep 2006 15:34:02 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><FONT color=#0000ff size=2><SPAN 
class=337382315-29092006>When I was working with Oracle and needed to store XML 
documents in the database I defined the column type as LONG RAW. Then I was able 
to stream the data into the table by using the following:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT color=#0000ff size=2><SPAN 
class=337382315-29092006></SPAN></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><FONT color=#008080 size=2><SPAN 
class=337382315-29092006>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PreparedStatement

statement = connection.prepareStatement("insert into DOCUMENTSTORE 
values(?,?)");</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT color=#008080><FONT size=2><SPAN 
class=337382315-29092006>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByteArrayInputStream

stream = new 
ByteArrayInputStream(documentData);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

statement.setBinaryStream(1, stream, 
documentData.length);</SPAN></FONT><BR></FONT></DIV>
<DIV dir=ltr align=left><FONT color=#008080><FONT color=#0000ff><FONT

size=2><SPAN class=337382315-29092006>To get the data out of the&nbsp;table I

used the following:</SPAN></FONT></FONT></FONT></DIV>
<DIV dir=ltr align=left><FONT><FONT><SPAN class=337382315-29092006></SPAN><FONT

size=2><FONT color=#008080><SPAN 
class=337382315-29092006>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; connection
= 
this.getConnection();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; statement
= 
connection.prepareStatement("select DOCUMENT from DOCUMENTSTORE where ID = 
?");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; statement.setObject(1, 
primaryKey);</SPAN></FONT></FONT></FONT></FONT></DIV>
<DIV dir=ltr align=left><FONT><FONT><FONT size=2><FONT color=#008080><SPAN

class=337382315-29092006></SPAN></FONT></FONT></FONT></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><FONT><FONT><FONT size=2><FONT color=#008080><SPAN

class=337382315-29092006>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[]
documentData 
= null;</SPAN></FONT></FONT></FONT></FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV dir=ltr align=left><FONT><FONT><FONT size=2><FONT color=#008080><SPAN

class=337382315-29092006>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ResultSet result
= 
statement.executeQuery();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result.next())

{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; documentData
= 
result.getBytes(1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
}</SPAN></FONT></FONT></FONT></FONT></DIV>
<DIV dir=ltr align=left><FONT><FONT><FONT size=2><FONT color=#008080><SPAN

class=337382315-29092006></SPAN></FONT></FONT></FONT></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><FONT><FONT><FONT color=#0000ff size=2><SPAN

class=337382315-29092006><SPAN 
class=337382315-29092006></SPAN></SPAN></FONT></FONT>&nbsp;</DIV></FONT>
<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>
Friday, 
September 29, 2006 5:16 AM<BR><B>To:</B> 
user-java@ibatis.apache.org<BR><B>Subject:</B> Scanning byte 
array<BR></FONT><BR></DIV>
<DIV></DIV><BR>Hi; <BR><BR>I have a method which return a byte
array from a BLOB 
(Oracle) : <BR><BR>public static byte[] getBLOB(int id, Connection conn) throws

Exception { <BR>ResultSet rs = null; <BR>PreparedStatement pstmt = null; 
<BR>String query = "SELECT data FROM Table1 WHERE id = ?"; <BR>try { <BR>pstmt
= 
conn.prepareStatement(query); <BR>pstmt.setInt(1, id); <BR>rs = 
pstmt.executeQuery(); <BR>rs.next(); <BR>Blob blob = rs.getBlob(1); <BR>return

blob.getBytes(1, (int) blob.length()); <BR>} finally { <BR>rs.close(); 
<BR>pstmt.close(); <BR>conn.close(); <BR>} <BR>} <BR><BR>}
<BR><BR>I must to 
scan the byte array position by position for extracting of the <BR>data 
contained into this array for a display in using a GUI. <BR>Which is the best 
(performance) solution to implemente this ? <BR><BR>Regards; <BR><BR><BR><BR>--

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


Mime
View raw message