开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜