Results 1 to 2 of 2
  1. #1
    evan087 is offline Member
    Join Date
    Aug 2012
    Posts
    6
    Rep Power
    0

    Default Write Byte Array to BLOB field in database

    Hi

    I am trying to write a byte array to a blob field in my database.

    Below code is not working for me because the object is actually 902 bytes, however, the database tells me that it is 11 bytes once committed.

    Can someone please help me to write to the blob field in my database?

    Java Code:
    protected void addFingerprint(byte[] fingerprintBytes)
        {
            Statement stat;
            
            try
            {  
                updateQuery = "UPDATE " + currentTable + " SET CLERK_FINGERPRINT_DATA_BLOB = '" + fingerprintBytes + "' WHERE " + data.getColumnName(0) + " = " + data.getValueAt(data.getSelectedRow(), 0) + ";";
                stat = connection.createStatement();
                stat.executeUpdate(updateQuery); 
                System.out.println(updateQuery);
                
                JOptionPaneCustom jOptionPane = new JOptionPaneCustom();      
                jOptionPane.showDialog(null, "<HTML>Fingerprint has been <b>successfully created!!</HTML>", "New fingerprint", 0.046, JOptionPane.OK_OPTION);  
            }
                    
            catch(Exception x)
            {
                JOptionPane.showMessageDialog(null, x, "UPDATE ERROR", JOptionPane.ERROR_MESSAGE);
                updateErrorOccurred = true;
            }
        }

  2. #2
    evan087 is offline Member
    Join Date
    Aug 2012
    Posts
    6
    Rep Power
    0

    Default Re: Write Byte Array to BLOB field in database

    I have managed to resolve the issue by making the modifications below.

    Java Code:
    try
    {  
                Blob blob = new SerialBlob(fingerprintBytes);
                updateQuery = "UPDATE " + currentTable + " SET CLERK_FINGERPRINT_DATA_BLOB = ?" + " WHERE " + data.getColumnName(0) + " = " + data.getValueAt(data.getSelectedRow(), 0) + ";";
                stat = connection.prepareStatement(updateQuery);
                stat.setBlob(1, blob);
                stat.execute(); 
                System.out.println(updateQuery);
                
                JOptionPaneCustom jOptionPane = new JOptionPaneCustom();      
                jOptionPane.showDialog(null, "<HTML>Fingerprint has been <b>successfully created!!</HTML>", "New fingerprint", 0.046, JOptionPane.OK_OPTION);  
    }

Similar Threads

  1. Split the BLOB DATA based on byte array.
    By yuvipoy in forum New To Java
    Replies: 5
    Last Post: 10-21-2013, 01:00 PM
  2. Replies: 0
    Last Post: 06-28-2013, 09:17 AM
  3. loading blob data in database
    By newbie123 in forum JDBC
    Replies: 5
    Last Post: 12-21-2011, 04:50 PM
  4. Replies: 1
    Last Post: 10-21-2011, 12:55 PM
  5. write/read two byte arrays to one file- help!
    By leshep in forum New To Java
    Replies: 2
    Last Post: 11-27-2009, 11:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •