0

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");
		}
		
	}
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by masijade
0

What exception? The full stack trace, please.

And add a stacktrace to that first catch block, as well. Besides, getting one exception may close the resultset which would lead to the catch block simply throwing another exception.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.