Question

I am developing a project with the sdk fingerprint of Griaule , and as a start I'm creating a program without a GUI that allows the user to scan his fingerprint and store it in a mysql database already created earlier. I'm here to ask you a hand with regard to storing the fingerprint in the database. In the program I created, I captured the fingerprint, I extracted the template from the fingerprint through a function I call extract () . After that I should call another function , enroll (), which allows me to save the fingerprint in a database. Even looking at the SDK examples I did not understand how it works, can someone help me? thanks in advance! :)

public void enroll() {
   try {
       //Inserts the template on the database
       enrollStmt.setBinaryStream(1,new ByteArrayInputStream(template.getData()), template.getData().length);
       enrollStmt.executeUpdate();

       //Picks the ID generated for it. 
       ResultSet rs = insertedIdStmt.executeQuery();
       rs.next();
       ui.writeLog("Fingerprint enrolled with id = "+Integer.toString(rs.getInt(1)));

   } catch (SQLException e) {
       ui.writeLog("Error enrolling template");
   }
}
Was it helpful?

Solution

It is saving the finger print data as BLOB in the database. Blob (Binary Large Object) is nothing but a byte array representation of information, mainly used to store images etc in database. In your case, the fingerprint information is being stored.

enrollStmt.setBinaryStream(1,new ByteArrayInputStream(template.getData()), template.getData().length);

In this line, the bytearrayinputstream is created using the data in the template object. template.getData is giving you the byte[] representation of the fingerprint information. Then the byte[] is getting saved in database, by

enrollStmt.executeUpdate();

Whereas, the following query gives you the id for the data stored, for your use.

 ResultSet rs = insertedIdStmt.executeQuery();

OTHER TIPS

Ok thank you very much Hirak , so I open a new connection with a function I created called initdb () , structured as follows:

private void initDB() {

    try {
           //Loads the JDBC driver. 
           Class.forName("com.mysql.jdbc.Driver").newInstance();

           /**Connection to the Database.*/
           Connection db;
           String user = "root";
           String password = ""; 

           // connect to a memory database
           db = DriverManager.getConnection("jdbc:mysql://localhost:3306/impronte?user=" + user + "&password=" + password);

           Statement stm = (Statement) db.createStatement();

         //Creates the statements that will be executed on the database,
           enrollStmt = db.prepareStatement("INSERT INTO persona(template) values(?)");
           insertedIdStmt = db.prepareStatement("SELECT MAX(ID) FROM persona");

       } catch (Exception e) {
           System.out.println("Error connecting to the database.");
           System.out.println(e.getMessage());
       }

}

and inside the enroll function this code, but nevertheless gives me the error("Error enrolling template"):

public void enroll ( Template template ) throws GrFingerJavaException {
   try {
           //Inserts the template on the database
           enrollStmt.setBinaryStream(1,new ByteArrayInputStream(template.getData()), template.getData().length);
           enrollStmt.executeUpdate();

           //Picks the ID generated for it. 
           ResultSet rs = insertedIdStmt.executeQuery();
           rs.next();
           System.out.println("Fingerprint enrolled with id = "+Integer.toString(rs.getInt(1)));

           System.out.println("Fingerprint enrolled");

       } catch (SQLException e) {
           System.out.println("Error enrolling template");
       }
}

You need to set the template to the template class of the sdk you are using before calling the binaryStream, see what I meant: Line 6 if I'm correct.

public void enroll ( Template template ) throws GrFingerJavaException {  
     try {

       //Inserts the template on the database

        Template temp = template;
         if(temp != null){
           byte[] b = temp.serialize();   
           enrollStmt.setBytes(1, b); 
           }

        enrollStmt.executeUpdate();

       //Picks the ID generated for it. 
       ResultSet rs = insertedIdStmt.executeQuery();
       rs.next();
       System.out.println("Fingerprint enrolled with id = "+Integer.toString(rs.getInt(1)));

       System.out.println("Fingerprint enrolled");

   } catch (SQLException e) {
       System.out.println("Error enrolling template");
   }

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top