You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by soussou97 <db...@yahoo.fr> on 2006/09/29 14:15:47 UTC
Scanning byte array
Hi;
I have a method which return a byte array from a BLOB (Oracle) :
public static byte[] getBLOB(int id, Connection conn) throws Exception {
ResultSet rs = null;
PreparedStatement pstmt = null;
String query = "SELECT data FROM Table1 WHERE id = ?";
try {
pstmt = conn.prepareStatement(query);
pstmt.setInt(1, id);
rs = pstmt.executeQuery();
rs.next();
Blob blob = rs.getBlob(1);
return blob.getBytes(1, (int) blob.length());
} finally {
rs.close();
pstmt.close();
conn.close();
}
}
}
I must to scan the byte array position by position for extracting of the
data contained into this array for a display in using a GUI.
Which is the best (performance) solution to implemente this ?
Regards;
--
View this message in context: http://www.nabble.com/Scanning-byte-array-tf2356548.html#a6563833
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
Re: Scanning byte array
Posted by soussou97 <db...@yahoo.fr>.
Hi Nathan;
Yes I would like to display the data via a GUI, so how I use a buffered
reader to read the data ? Have you a example ?
Thank's
Nathan Maves-2 wrote:
>
> When you say scan are you looking for some specific bytes? If not
> just use a buffered reader to read and display the data.
>
> On 9/29/06, soussou97 <db...@yahoo.fr> wrote:
>>
>> Hi;
>>
>> I have a method which return a byte array from a BLOB (Oracle) :
>>
>> public static byte[] getBLOB(int id, Connection conn) throws Exception {
>> ResultSet rs = null;
>> PreparedStatement pstmt = null;
>> String query = "SELECT data FROM Table1 WHERE id = ?";
>> try {
>> pstmt = conn.prepareStatement(query);
>> pstmt.setInt(1, id);
>> rs = pstmt.executeQuery();
>> rs.next();
>> Blob blob = rs.getBlob(1);
>> return blob.getBytes(1, (int) blob.length());
>> } finally {
>> rs.close();
>> pstmt.close();
>> conn.close();
>> }
>> }
>>
>> }
>>
>> I must to scan the byte array position by position for extracting of the
>> data contained into this array for a display in using a GUI.
>> Which is the best (performance) solution to implemente this ?
>>
>> Regards;
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Scanning-byte-array-tf2356548.html#a6563833
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Scanning-byte-array-tf2356548.html#a6597309
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
RE: Scanning byte array
Posted by soussou97 <db...@yahoo.fr>.
Hi Christopher;
OK but I must only read the byte[] or write it also in using
ByteArrayOutputStream or both (read & write) ?
Thank's
Christopher.Mathrusse wrote:
>
>
>
>
>
>
> Once you have a byte[] you can read it using a ByteArrayInputStream and
> you can write it using ByteArrayOutputStream.
> You should look at the JavaDocs to learn more about these
> classes.
>
> For reading the byte[] you could, for example, do the
> following:
>
>
> java.sql.Connection connection = this.getConnection();
> java.sql.PreparedStatement statement =
> connection.prepareStatement("select data from
> DATASTORE where ID = ?");
> statement.setObject(1, primaryKey);
> byte[] documentData = null;
>
> java.sql.ResultSet result = statement.executeQuery();
> if
> (result.next()) {
> documentData = result.getBytes(1);
> }
>
> java.io.ByteArrayInputStream bis = new
> java.io.ByteArrayInputStream(documentData);
>
> java.io.BufferedReader in
> = new
> java.io.BufferedReader(new java.io.InputStreamReader(bis));
>
> String str = null;
> do
> {
> str = in.readLine();
> // do something
> here
> } while(str !=
> null);
>
>
>
> From: soussou97 <dboussebha@yahoo.fr>
> [mailto:soussou97 <dboussebha@yahoo.fr>] Sent: Monday, October
> 02, 2006 1:20 AM To: user-java@ibatis.apache.org Subject:
> RE: Scanning byte array
> Hi Christopher ; OK for your example but imagined that
> you do not have of documents but of data, so firstly to get the data out
> of
> the table as into the example : connection = this.getConnection();
> statement = connection.prepareStatement("select data from DATASTORE
> where ID = ?"); statement.setObject(1, primaryKey); byte[] documentData
> = null; ResultSet result = statement.executeQuery(); if (result.next())
> { Data = result.getBytes(1); } Next you make how to extract the
> data inside of array (which can be : integer, string, etc...) ?
> Regards; Christopher.Mathrusse wrote: > >
> > > > > > 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: > >
> PreparedStatement > statement = connection.prepareStatement("insert
> into
> DOCUMENTSTORE > values(?,?)"); >
> ByteArrayInputStream > stream = new >
> ByteArrayInputStream(documentData); >
> statement.setBinaryStream(1, stream, > documentData.length); > To
> get the data out of the table I > used the following: >
> connection = > this.getConnection();
> statement = >
> connection.prepareStatement("select DOCUMENT from DOCUMENTSTORE where ID =
> > ?"); statement.setObject(1, >
> primaryKey); > > byte[]
> documentData > = null; > >
> ResultSet result = >
> statement.executeQuery(); if >
> (result.next()) > {
> documentData = > result.getBytes(1);
> > } > > > > > From:
> soussou97 <dboussebha@yahoo.fr> > [mailto:soussou97
> <dboussebha@yahoo.fr>] Sent: Friday, > September 29, 2006 5:16 AM
> To: > user-java@ibatis.apache.org Subject: Scanning byte > array
> > Hi; I have a method which return a byte array from a BLOB >
> (Oracle) : public static byte[] getBLOB(int id, Connection conn) throws
> >
> Exception { ResultSet rs = null; PreparedStatement pstmt = null; >
> String
> query = "SELECT data FROM Table1 WHERE id = ?"; try { pstmt = >
> conn.prepareStatement(query); pstmt.setInt(1, id); rs = >
> pstmt.executeQuery(); rs.next(); Blob blob = rs.getBlob(1); return >
> blob.getBytes(1, (int) blob.length()); } finally { rs.close(); >
> pstmt.close(); conn.close(); } } } I must to > scan the byte array
> position by position for extracting of the data > contained into this
> array for a display in using a GUI. Which is the best > (performance)
> solution to implemente this ? Regards; -- > View this message in
> context:
> > http://www.nabble.com/Scanning-byte-array-tf2356548.html#a6563833
> Sent
> > from > the iBATIS - User - Java mailing list archive at
> Nabble.com. > > > > -- View this message
> in context:
> http://www.nabble.com/Scanning-byte-array-tf2356548.html#a6597501
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>
>
>
--
View this message in context: http://www.nabble.com/Scanning-byte-array-tf2356548.html#a6610758
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
RE: Scanning byte array
Posted by soussou97 <db...@yahoo.fr>.
Hi Christopher ;
OK for your example but imagined that you do not have of documents but of
data, so firstly to get the data out of the table as into the example :
connection = this.getConnection();
statement = connection.prepareStatement("select data from
DATASTORE where ID = ?");
statement.setObject(1, primaryKey);
byte[] documentData = null;
ResultSet result = statement.executeQuery();
if (result.next()) {
Data = result.getBytes(1);
}
Next you make how to extract the data inside of array (which can be :
integer, string, etc...) ?
Regards;
Christopher.Mathrusse wrote:
>
>
>
>
>
>
> 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:
>
> PreparedStatement
> statement = connection.prepareStatement("insert into DOCUMENTSTORE
> values(?,?)");
> ByteArrayInputStream
> stream = new
> ByteArrayInputStream(documentData);
> statement.setBinaryStream(1, stream,
> documentData.length);
> To get the data out of the table I
> used the following:
> connection =
> this.getConnection(); statement =
> connection.prepareStatement("select DOCUMENT from DOCUMENTSTORE where ID =
> ?"); statement.setObject(1,
> primaryKey);
>
> byte[] documentData
> = null;
>
> ResultSet result =
> statement.executeQuery(); if
> (result.next())
> { documentData =
> result.getBytes(1);
> }
>
>
>
>
> From: soussou97 <dboussebha@yahoo.fr>
> [mailto:soussou97 <dboussebha@yahoo.fr>] Sent: Friday,
> September 29, 2006 5:16 AM To:
> user-java@ibatis.apache.org Subject: Scanning byte
> array
> Hi; I have a method which return a byte array from a BLOB
> (Oracle) : public static byte[] getBLOB(int id, Connection conn) throws
> Exception { ResultSet rs = null; PreparedStatement pstmt = null;
> String query = "SELECT data FROM Table1 WHERE id = ?"; try { pstmt =
> conn.prepareStatement(query); pstmt.setInt(1, id); rs =
> pstmt.executeQuery(); rs.next(); Blob blob = rs.getBlob(1); return
> blob.getBytes(1, (int) blob.length()); } finally { rs.close();
> pstmt.close(); conn.close(); } } } I must to
> scan the byte array position by position for extracting of the data
> contained into this array for a display in using a GUI. Which is the best
> (performance) solution to implemente this ? Regards; --
> View this message in context:
> http://www.nabble.com/Scanning-byte-array-tf2356548.html#a6563833 Sent
> from
> the iBATIS - User - Java mailing list archive at Nabble.com.
>
>
>
>
--
View this message in context: http://www.nabble.com/Scanning-byte-array-tf2356548.html#a6597501
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
Re: Scanning byte array
Posted by Nathan Maves <na...@gmail.com>.
When you say scan are you looking for some specific bytes? If not
just use a buffered reader to read and display the data.
On 9/29/06, soussou97 <db...@yahoo.fr> wrote:
>
> Hi;
>
> I have a method which return a byte array from a BLOB (Oracle) :
>
> public static byte[] getBLOB(int id, Connection conn) throws Exception {
> ResultSet rs = null;
> PreparedStatement pstmt = null;
> String query = "SELECT data FROM Table1 WHERE id = ?";
> try {
> pstmt = conn.prepareStatement(query);
> pstmt.setInt(1, id);
> rs = pstmt.executeQuery();
> rs.next();
> Blob blob = rs.getBlob(1);
> return blob.getBytes(1, (int) blob.length());
> } finally {
> rs.close();
> pstmt.close();
> conn.close();
> }
> }
>
> }
>
> I must to scan the byte array position by position for extracting of the
> data contained into this array for a display in using a GUI.
> Which is the best (performance) solution to implemente this ?
>
> Regards;
>
>
>
> --
> View this message in context: http://www.nabble.com/Scanning-byte-array-tf2356548.html#a6563833
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>