In following code ,I have initialized column to empty blob. But when I try to retrieve the blob,i get an exception.Can anybody help me out??
_____________________________________________________
import java.sql.*;
class test
{
public static void main(String[] args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn= DriverManager.getConnection ("jdbc:odbc:dixit","scott","tiger");
PreparedStatement st=conn.prepareStatement("insert into survey values (?,EMPTY_BLOB())");
st.setInt(1,1);
int count=st.executeUpdate();
Statement st1=conn.createStatement();
System.out.println("Hi");
ResultSet rs=st1.executeQuery("Select name from survey");
while(rs.next())
{
//int i=rs.getInt(1);
//System.out.println("Hi"+i);
try
{
// Get as a BLOB
Blob aBlob = rs.getBlob(1);
byte[] allBytesInBlob = aBlob.getBytes(1, (int) aBlob.length());
}
catch(Exception ex)
{
// The driver could not handle this as a BLOB...
// Fallback to default (and slower) byte[] handling
byte[] bytes = rs.getBytes(1);
}
}
}
catch(Exception e)
{
System.out.println("Error");
}
}
}