开发者

How to send the data (BLOB & CLOB) to the database from java

开发者 https://www.devze.com 2022-12-21 16:19 出处:网络
The table columns have the data type BLOB and CLOB. What are the corresponding Java data types? I am u开发者_运维技巧sing MySQL database.BLOB and CLOB are bytes strings stored in database.

The table columns have the data type BLOB and CLOB.

What are the corresponding Java data types?

I am u开发者_运维技巧sing MySQL database.


BLOB and CLOB are bytes strings stored in database.

In MySQL, you can have an entity with a field of byte array representing your BLOB / CLOB.

E.g.

class MyBlob implements Serializable {

  byte[] myBlobField;

  //Setter
  public void setMyBlobField(byte[] myBlobField) {
    this.myBlobField = myBlobField;
  }

  //Getter
  public byte[] getMyBlobField() {
     return myBlobField;
  }
}

On JDBC, create a PreparedStatement and do something of this effect:

 MyBlob blob = ....;
 PreparedStatement ps = ....;
 ps.setByte(1, blob.getMyBlobField());

 ps.execute();
 //Handle Exceptions...close...etc.
0

精彩评论

暂无评论...
验证码 换一张
取 消