Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / November 2003

Tip: Looking for answers? Try searching our database.

JDBC : SQLException -> "Stream has already been closed"

Thread view: 
Matt C - 21 Nov 2003 17:38 GMT
I use the following code to query a column that contains a long data
type in an Oracle DB.

*******

 String SQL = "select .....";
 stmt.execute(SQL);
 rs = stmt.getResultSet();

 while (rs.next()) {
     String projectID = rs.getString("PROJECT_ID");
     Grant  g = (Grant) grantsIndexedById.get(projectID);
     if (g != null ) {
//       g.addResearchData(rs);
        g.setResearchTitle(rs.getString("DESCR254_MIXED"));

        InputStream in = rs.getAsciiStream("DESCRLONG");
        StringBuffer sb = new StringBuffer();
        int b;
        while ((b=(int)in.read())!=-1){
            sb.append((char)b);
        }

        g.setResearchSummary(sb.toString());
        g.setResearchField(rs.getString("XLATLONGNAME"));

     }

< ... more code here ...>

public void addResearchData(ResultSet rs) throws SQLException,
IOException {

   researchField  = rs.getString("XLATLONGNAME");
   researchTitle = "RESEARCH TITLE GOES HERE";

   // THE FOLLOWING LINE IS WHERE THE EXCEPTION GETS THROWN !
   InputStream in = rs.getAsciiStream("DESCRLONG");
   StringBuffer sb = new StringBuffer();
   int b;
   while ((b=(int)in.read())!=-1){
       sb.append((char)b);
   }
   researchSummary = sb.toString();
}

**************

The code works fine. But when I comment out everything inside the
first "if" statement and un-comment out the line
"g.addResearchData(rs)";

I receive the SQLException "Stream has already been closed" on the
line:

 InputStream in = rs.getAsciiStream("DESCRLONG");

In the addResearchData() method.

In other words when I move the code into a separate method I receive
the SQLException. Has anyone seen this before? Can anyone offer an
explanation?

Thanks in advance,
Matt
Joe Weinstein - 21 Nov 2003 18:16 GMT
> I use the following code to query a column that contains a long data
> type in an Oracle DB.

Hi. It may have to do with the fact that you select different columns
and/or in a different order. Some JDBC drivers only allow columns to be
retrieved in the order they come from the query, especially when
a LONG/BLOB column is included. Try getting the rs.getString("XLATLONGNAME")
and rs.getString("DESCR254_MIXED") done the same in each mode, and you
will find the solution.

Joe Weinstein at BEA

> *******
>
[quoted text clipped - 58 lines]
> Thanks in advance,
> Matt
Matt C - 24 Nov 2003 14:16 GMT
You hit the nail on the head! I guess you learn something new everyday.
Thanks!

> > I use the following code to query a column that contains a long data
> > type in an Oracle DB.
[quoted text clipped - 70 lines]
> > Thanks in advance,
> > Matt


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.