Announcement Announcement Module
Collapse
No announcement yet.
storing byte[] into mysql with spring jdbc Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • storing byte[] into mysql with spring jdbc

    I am in the process of writing an application that would get a byte[] data taken from a fingerprint device and store that data into mysql for a time and attendance system.

    I have tried to follow through the imagedb sample that came with spring but my data isn't updating.

    The concerned code is as follows:

    Code:
        class UpdatePrint extends JdbcTemplate {
        	LobHandler lobHandler;
        	String sql;
        	
        	public UpdatePrint(DataSource datasource,String sql){
        		super(datasource);
        		this.sql = sql;
        		this.lobHandler = new DefaultLobHandler();
        	}
    
        	public void setPrint(String empid,ByteArrayInputStream inStream){
        		System.out.println("in setPrint...");
        		getJdbcTemplate().execute(this.sql,new UpdateBlobCallback(lobHandler,empid,inStream));
        	}
        }
    
    
        class UpdateBlobCallback extends AbstractLobCreatingPreparedStatementCallback {
        	private String empid;
        	private ByteArrayInputStream fingerprint;
        	
        	public UpdateBlobCallback(LobHandler lobHandler, String empid, ByteArrayInputStream inStream){
        		super(lobHandler);
        		this.empid = empid;
        		this.fingerprint = inStream;
        	}
        	protected void setValues(PreparedStatement ps,LobCreator lobCreator) throws SQLException {
        		System.out.println("id:"+this.empid);
        		System.out.println("data:"+this.fingerprint);
        		ps.setString(1, this.empid);
        		lobCreator.setBlobAsBinaryStream(ps, 2, fingerprint, fingerprint.available());
        		//    		ps.setBlob(2, new ByteArrayInputStream(this.fingerprint));
        	}
        }



    at first i tried using the byte[] directly, using ps.setBytes(byte[]), but a check on the actual table after the insertion still has my column as null. I've also tried ps.setBlob... but still, selecting the data from mysql directly yields a null value on the particular column.

    Your valued inputs are well appreciated.


    By the way, this is how I converted the byte[] into the stream:

    Code:
    byte[] fprint = regTemplate.getData();  // set fprint with fingerprint template
    ByteArrayInputStream inStream = new ByteArrayInputStream(fprint);

  • #2
    As of this moment, I'm still stuck with this problem. I've tried using SqlLobValue but still the same effect.

    I would really appreciate any help on this.

    Comment


    • #3
      Originally posted by wowiesy View Post
      As of this moment, I'm still stuck with this problem. I've tried using SqlLobValue but still the same effect.

      I would really appreciate any help on this.
      Hello!

      I have the same problem. Have you been solve it yet?

      Best regards

      Comment

      Working...
      X