Easiest way to convert a Blob into a byte array

前端 未结 2 1556
轮回少年
轮回少年 2020-12-01 05:29

what is the easiest way to convert a Blob into a byte array?I am using MYSQL and i want to convert a Blob datatype into a byte array.

Iam using java programming lang

相关标签:
2条回答
  • 2020-12-01 05:34

    the mySql blob class has the following function :

    blob.getBytes

    use it like this:

    //(assuming you have a ResultSet named RS)
    Blob blob = rs.getBlob("SomeDatabaseField");
    
    int blobLength = (int) blob.length();  
    byte[] blobAsBytes = blob.getBytes(1, blobLength);
    
    //release the blob and free up memory. (since JDBC 4.0)
    blob.free();
    
    0 讨论(0)
  • 2020-12-01 05:38

    The easiest way is this.

    byte[] bytes = rs.getBytes("my_field");
    
    0 讨论(0)
提交回复
热议问题