logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

Re: Help - lo_close: invalid large obj descriptor: msg#00259

db.postgresql.jdbc

Subject: Re: Help - lo_close: invalid large obj descriptor

Toby,

You need to have autocommit turned off in order to use large objects. If I add a call to setAutocommit(false) for the connection everything works fine.

thanks,
--Barry


Toby wrote:
I've read the docs, I've searched the web.

I'm running PGSql 7.3.4 under Cygwin 1.3.22.1, J2SE 1.4.2, latest stable JDBC v3 drivers (pg73jdbc3.jar). This is all running on the same machine, a dual AMD with 1GB memory.

Accessing the database works fine, but when I try to write to a newly created LargeObject it always fails with

org.postgresql.util.PSQLException - FastPath call returned ERROR: lo_write: invalid large obj descriptor (0)

The code below illustrates this.

The code is actually going to be used within a Tomcat webapp, but I had to use Jdbc3ConnectionPool since that was the only pool that returned connections that were castable to a PGConnection. I get the same error from inside and outside Tomcat. Thought the error might be related to permissions writing large objects so I tried the following which didn't help.

GRANT ALL ON "pg_largeobject" TO "web";

I also tried not using the connection pool, and instead just using the straight DriverManager.getConnection() instead, but that fails on the lo.write() call too.

I've had large objects working fine on another project (same dev machine) a coupla years ago (pg 7.2.x), so I don't think its a case of HOW I'm doing it, I suspect there's a bug.

Can someone shed some light?


import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.postgresql.PGConnection;
import org.postgresql.jdbc3.Jdbc3ConnectionPool;
import org.postgresql.largeobject.LargeObject;
import org.postgresql.largeobject.LargeObjectManager;

public class TestHarness
{
public static void main(String[] args)
{
LargeObject lo = null;
Connection conn = null;
try
{
//get a connection that's PGConnection-castable.
//PoolingDataSource- tried 'n died
//Jdbc3PoolingDataSource- tried 'n died
Jdbc3ConnectionPool source = new Jdbc3ConnectionPool();
source.setServerName("ash");
source.setDatabaseName("adserver");
source.setUser("web");
source.setPassword("web");
source.setDefaultAutoCommit(false);

//just to be sure - it always says true so that's good
//Class.forName("org.postgresql.Driver");
//conn = DriverManager.getConnection("jdbc:postgresql://ash/adserver", "web", "web");
conn = source.getConnection();
System.out.println(conn.getAutoCommit());

//this only works for connections from Jdbc3ConnectionPool
PGConnection pgconn = (PGConnection)conn;

//create the largeobject and prepare to write to it
LargeObjectManager lom = pgconn.getLargeObjectAPI();
int oid = lom.create(LargeObjectManager.READ | LargeObjectManager.WRITE);
lo = lom.open(oid, LargeObjectManager.WRITE);

//the thing to write
File file = new File("D:\\downloads\\images\\banner.GIF");
FileInputStream fis = new FileInputStream(file);

//prepare a buffer (small enough to force multiple loop iterations
//so we test it properly)
byte buff[] = new byte[1024];

//now write the image
int bytes_read;
while ((bytes_read = fis.read(buff, 0, buff.length)) > 0)
{
System.out.println("bytes_read=" + bytes_read);
//ERROR HAPPENS NEXT
//ERROR HAPPENS NEXT
//ERROR HAPPENS NEXT
lo.write(buff, 0, bytes_read);
}

//clean up
fis.close();
System.out.println("done");
}
catch (Exception e)
{
System.out.println(e.getClass().getName() + " - " + e.getMessage());
}
finally
{
if (lo != null) try{lo.close();}catch (SQLException e){}
if (conn != null) try{conn.close();}catch (SQLException e){}
}
}
}






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






Only community members can participate in forum threads. You must Register or log in to contribute.

<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

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

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo