JDBC- CLOB

JDBC - CLOB

We use CLOB objects to store character data like txt files,word files etc

We have following methods to Save & Retrive CLOB Objects

To Save

  • void setCharacterStream(int parameterIndex, InputStream x)

  • void setCharacterStream(int parameterIndex, InputStream x, int length)

  • void setClob(int index, Clob x)

  • void setClob(int index,InputStream is)

To Retrive

  • Blob getClob(int columnIndex)

  • Blob getClob(String columnLabel)

  • InputStream getCharacterStream (int columnIndex)

  • InputStream getCharacterStream (String column)

Steps:

1.Read File data by using InputStream

FileInputStream fis=new FileInputStream("d:\\g.jpg");

2.Create PreparedStatement Object to write insert image query

PreparedStatement ps=con.prepareStatement("insert into filetable values(?,?)");

3.Set parameter values

ps.setInt(1, 101);
ps.setCharacterStream (2,fis);

4.Execute Query

int i=ps.executeUpdate();

5.To get image from table execute Select Quey , call on rs object

FileInputSteam fs=       rs. getCharacterStream (  column");