Search code examples
javamysqlfingerprint

Error matching finger data


I am currently working on a simple java project where I am scanning finger prints from user, converting it to string, storing it in database (MySQL) using Text, retrieving them back from database and comparing it with new finger print to perform match operation. The problem is for same person, it is not recognizing the finger print data. For capturing finger data, I am using Mantra's MFS100 finger print device!!! Here is the code snap:

byte[] ISOTemplate = null;

/* Finger data contains
 * byte[] ISOTemplate;
 */

FingerData data = new FingerData();

/*It will now scan fingerprints from device*/

int ret = mfs100.AutoCapture(data,timeout,false,false);

//Initializing local ISOTemplate
ISOTemplate = new byte[data.ISOTemplate().length];
System.arraycopy(data.ISOTemplate(), 0, ISOTemplate, 0, data.ISOTemplate().length);

//Storing it in database
String str = new String(ISOTemplate);
Connection con = (Connection) 
DriverManager.getConnection("jdbc:mysql://localhost:3306/db","user","pass");
PreparedStatement ps = con.prepareStatement("update datatable set fingerscan = ? where empID like '123'");
ps.setString(1,str);
ps.executeUpdate();

Until here, everything is working fine. The problem is here:

PreparedStatement ps = con.prepareStatement("select fingerscan from datatable where empID like '123'");            
ResultSet rs = ps.executeQuery();
while(rs.next()){
       String tmp = rs.getString("fingerscan");
       ISOTemplate = tmp.getBytes();
}

//captures new data from user
int ret = mfs100.AutoCapture(data, timeout,  false, false);
if(ret == 0){
    int score = 0;
    score = mfs100.MatchISO(data.ISOTemplate(), ISOTemplate);                
    System.out.println("Score:"+score);
    if(score > 14000){
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Success:"+score, ButtonType.OK);
    alert.show();
    }else if (score >= 0 && score < 14000) {
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Failure:"+score, ButtonType.OK);
    alert.show();
    }   
 } 

According to the device specification the match score shoud be greater than 14000. But in my case the score is only 1300 around. I have tried this:

How to save "Finger Print" in database

but still score is less than 14000.

I know the problem is when I am storing the finger data in mysql database the data is becoming useless. So please suggest me some ways to store the finger data into the database. Please help me increasing the match score.


Solution

  • Dont convert your byte array to string.

    In MySQL

    create a column with BLOB type

    Save template

    In Java use setBytes method of PreparedStatement

    PreparedStatement ps = con.prepareStatement("update datatable set fingerscan = ? where empID like '123'");
    ps.setBytes(1,ISOTemplate);
    ps.executeUpdate();
    

    Get template

    In Java use getBytes method of ResultSet

    PreparedStatement ps = con.prepareStatement("select fingerscan from 
    datatable where empID like '123'");            
    ResultSet rs = ps.executeQuery();
    while(rs.next()){
       String tmp = rs.getBytes(1);
       ISOTemplate = tmp.getBytes();
    }