cancel
Showing results for 
Search instead for 
Did you mean: 

How to read a byte data from maxdb data base

Former Member
0 Kudos

Dear All,

I have a issue in reading the data from database table.

I have a column named as templateData which contains the byte data (biometric template data, which comes from fingerprint device) which is DataType of LONG and CODE of BYTE.

I am not using the below to get the template data

Connection con = null;

Statement stmt = null;

ResultSet resultSet = null;

byte[] DbBioData = new byte[1024];

InitialContext ctx = new InitialContext();

if(ctx == null)

throw new Exception("Boom - No Context");

DataSource ds = (DataSource)ctx.lookup(db_drvstr);

con = ds.getConnection();

stmt = con.createStatement();

resultSet = stmt.executeQuery(db_query + " where SUBJECT_ID='"+ username +"'");

if(resultSet.next())

{

DbBioData = resultSet.getBytes(1);

_loc.infoT("verify", "verify::Got BioData From MAXDB" +DbBioData );

loc.infoT("verify", "verify::Query is: " +dbquery + " where SUBJECT_ID='"+ username +"'" );

}

But I am not getting the proper data, could anyone please tell me the way to read the biometric data from data base table.

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

Hi Kishore,

the data type LONG BYTE is the correct type for storing large binary data. Also the code to retrieve the byte value looks fine.

ResultSet resultSet = stmt.executeQuery(<your query>);

if(resultSet.next()){

byte [] DbBioData = resultSet.getBytes(1);

}

Maybe the insert of the binary data is the problem. Did you commit the insert? You can check the inserted data with SQLStudio. Select the table and right click on the binary column in the result table grid. In the context menu choose the entry "export cell to" -> "Zoom Window binary".

regards,

Marco Paskamp

lbreddemann
Active Contributor
0 Kudos

Hi Kishore,

is it me or is there no query definition in that code?

I see that you concatenate a "db_query" with a string to make up a WHERE clause, but the db_query is nowhere defined before.

So at least you should provide something like

stmt = con.createStatement("SELECT templateDate FROM <tablename> ");

before you do anything with the query.

Besides this: have you ever heard of SQL injections? Try to use BIND-variables instead of concatenating strings. Otherwise your application will spend much time just with parsing your queries...

Hmm... possibly the best thing you could do about this is to read the JAVA manual for MaxDB:

<a href="http://maxdb.sap.com/currentdoc/ef/2de883d47a3840ac4ebb0b65a599e5/content.htm">Java Manual (SAP Library - Interfaces)</a>

Best regards,

Lars

Edited by: Lars Breddemann on Dec 17, 2007 1:12 PM - corrected link