Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Problem with LargeObject/jdbc when writing short (Repost): msg#00400

db.postgresql.jdbc

Subject: Problem with LargeObject/jdbc when writing short (Repost)

Hi group,

since my last mail made it through, I assume that the previous one
just magically diappeared. Here it is again:

I have a problem when trying to use the getInputStream()/getOutputStream()
methods of LargeObject. The problem is demonstrated by the code I append
to this post.

There I create a LargeObject and put there all numbers from 100 to
2000 as shorts. Afterwards, I re-open this object by its oid, read
itout and print it on the screen.

The funny thing is that the program stops after writing the 127 on the
screen. So, either the writing was silently stopping with number 128,
or the reader creates a EOFException when the 8th bit was set.

The Postgresql version is 7.2.2, the jdbc driver is jdbc7.1-1.2.jar,
both directly from the SuSE 8.1 CD.

What is the cause of that and what can I do to get a correct behaviour?
Is it a bug or did I just not carefully read the manual?

Ciao

Ole

This is the Code:
---------------------------------8<------------------------------------------
import java.io.*;
import java.sql.*;
import org.postgresql.largeobject.*;

public class PgTest {
public static void main (String[] args) {
try {
Class.forName("org.postgresql.Driver");
Connection dbConn
= DriverManager.getConnection("jdbc:postgresql:ole", "ole", "nixda");
dbConn.setAutoCommit(false);
LargeObjectManager lobjm =
((org.postgresql.Connection)dbConn).getLargeObjectAPI();

int oid = lobjm.create(LargeObjectManager.READ
| LargeObjectManager.WRITE);
System.out.println("Oid is " + oid);

// *** 1st Step: write 1900 shorts ***
LargeObject wobj = lobjm.open(oid, LargeObjectManager.WRITE);
DataOutputStream dos = new DataOutputStream(wobj.getOutputStream());
for (short i = 100; i < 2000; i++) {
dos.writeShort(i);
}
dos.close();
wobj.close();
dbConn.commit();

// *** 2nd Step: read these shorts back from the same OID ***
LargeObject robj = lobjm.open(oid, LargeObjectManager.READ);
DataInputStream is = new DataInputStream(robj.getInputStream());
try {
while (true) {
System.out.println(is.readShort());
}
} catch (EOFException e) {
System.out.println("End of file reached.");
}
robj.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
qnx.openqnx.dev...    gcc.libstdc++.c...    solaris.opensol...    information-ret...    misc.misterhous...    web.catalyst.ge...    apache.webservi...    redhat.release....    hardware.lirc/2...    kernel.autofs/2...    technology.sust...    linux.vdr/2003-...    editors.lyx.gen...    org.user-groups...    netbsd.devel.pk...    xdg.devel/2004-...    version-control...    jakarta.slide.d...    debian.packages...    creativecommons...    ports.ppc.embed...    bug-tracking.bu...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe