Plz help!!

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 34
Reputation: srs_grp is an unknown quantity at this point 
Solved Threads: 0
srs_grp srs_grp is offline Offline
Light Poster

Plz help!!

 
0
  #1
Jan 6th, 2009
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??
_____________________________________________________
  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: Plz help!!

 
0
  #2
Jan 6th, 2009
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 251 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC