943,794 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 305
  • Java RSS
Jan 6th, 2009
0

Plz help!!

Expand Post »
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??
_____________________________________________________
Java Syntax (Toggle Plain Text)
  1. import java.sql.*;
  2. class test
  3. {
  4. public static void main(String[] args)
  5. {
  6. try
  7. {
  8. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  9. Connection conn= DriverManager.getConnection ("jdbc:odbc:dixit","scott","tiger");
  10. PreparedStatement st=conn.prepareStatement("insert into survey values (?,EMPTY_BLOB())");
  11. st.setInt(1,1);
  12. int count=st.executeUpdate();
  13.  
  14. Statement st1=conn.createStatement();
  15. System.out.println("Hi");
  16. ResultSet rs=st1.executeQuery("Select name from survey");
  17. while(rs.next())
  18. {
  19. //int i=rs.getInt(1);
  20. //System.out.println("Hi"+i);
  21. try
  22. {
  23. // Get as a BLOB
  24. Blob aBlob = rs.getBlob(1);
  25. byte[] allBytesInBlob = aBlob.getBytes(1, (int) aBlob.length());
  26. }
  27. catch(Exception ex)
  28. {
  29. // The driver could not handle this as a BLOB...
  30. // Fallback to default (and slower) byte[] handling
  31. byte[] bytes = rs.getBytes(1);
  32. }
  33.  
  34. }
  35.  
  36. }
  37. catch(Exception e)
  38. {
  39. System.out.println("Error");
  40. }
  41.  
  42. }
  43. }
Last edited by ~s.o.s~; Jan 8th, 2009 at 10:15 am. Reason: Added code tags, learn to use them.
Similar Threads
Reputation Points: 9
Solved Threads: 0
Light Poster
srs_grp is offline Offline
34 posts
since Sep 2008
Jan 6th, 2009
0

Re: Plz help!!

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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: multiple stack in one dimentional array using node/ linked list
Next Thread in Java Forum Timeline: does java support Multiple inheritence via interfaces





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC