Thread: SocketException

SocketException

From
Hicham Mouline
Date:
Hi,


postgres 6.5.1
postgres-jdbc 6.5.1
jdk 1.2 from blackdown.org
under linux 2.2.7 with glibc2.1


I'm using the postgres jdbc driver from one and only one of my daemon's
threads which regulary updates a database of companies data.
The postmaster and my daemon both run on localhost and postmaster runs
with  the -i switch.

The thread correctly connects to the database, creates a statement only
once.
Then it enters a loop which checks for companies info in a vector and
sends SQL queries either to UPDATE or to INSERT that particular company.

Sometimes this works, but most of the time it doesn't.
The error is the following:

An I/O error occured while reading from backend -
java.net.SocketException: Resource temporarily unavailable: Resource
temporarily unavailable       at postgresql.PG_Stream.ReceiveChar(Compiled Code)       at
postgresql.Connection.ExecSQL(CompiledCode)       at postgresql.jdbc2.Statement.execute(Compiled Code)       at
postgresql.jdbc2.Statement.executeQuery(CompiledCode)       at CompaniesDBThread.run(Compiled Code)
 




The name of my thread as you must have figured out is CompaniesDBThread.



Here is the thread's code:

-----------------------------------------------------------------
public void run() {Connection c = null;Statement st = null;ResultSet rs = null;long lastUpdate=0;final String dbHost =
"myhost";finalString dbName = "mydbname";
 

try { c=DriverManager.getConnection(...); st = c.createStatement(); System.out.println("connected to companies
database");}catch (SQLException e) { System.err.println("Could not connect to database"); System.err.println("error:
"+e.getMessage());System.err.println("Killing database thread."); return; }
 
do { for (int coIdx=0; coIdx<=Companies.size()-1; coIdx++) {   Company co = (Company)(Companies.elementAt(coIdx));
try{       rs = st.executeQuery("SELECT name FROM fund WHERE
 
name='"+co.name+"'");       boolean coExist = rs.next();       rs.close();       if ( coExist )    try {       rs =
st.executeQuery("SELECTname FROM fund WHERE
 
name='"+co.name+"'");       boolean coExist = rs.next();       rs.close();       if ( coExist )
st.executeUpdate(co.updateQuery());      else         st.executeUpdate(co.insertQuery());       st.close();      }
catch(Exception e) {e.printStackTrace();coIdx--;} }} while (interrupted());
 

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




The 1st part is the connection.
The 2nd part scans through 'Companies' vector. Depending on whether the
company exit, we send the appropriate query returned by one of the class'
two methods.

The above error sometimes happens during the call to the st.executeQuery,
and sometimes during the st.executeUpdate.
Two other errors eventually happen too:

A result was returned by the statement, when none was expected.       at
postgresql.jdbc2.Statement.executeUpdate(CompiledCode)       at CompaniesDBThread.run(Compiled Code)
 

or
Unknown Response Type (some weird characters)       at postgresql.Connection.ExecSQL(Compiled Code)       at
postgresql.jdbc2.Statement.execute(CompiledCode)       at postgresql.jdbc2.Statement.executeQuery(Compiled Code)
atCompaniesDBThread.run(Compiled Code)
 

But always after the 1st mentioned error (Resource temporarily
unavailable).





I have run another program to access the database, and it works without
any problem.

public class trial {
public static void main (String[] args) throws Exception {   Connection c = null;   Statement st = null;   ResultSet rs
=null;   final String dbHost = "...";   final String dbName = "...";
 
Class.forName("postgresql.Driver");c =DriverManager.getConnection(...); st = c.createStatement();
rs = st.executeQuery("SELECT name,ch,stockids FROM fund");while (rs.next()){    System.out.println(rs.getString(1));
System.out.println(rs.getString(3));}rs.close();st.close();c.close();}
}




I launched the postmaster with debug option -d 9 and there are no error
messages.

One thing though, I have been unable to download jdk 1.2 for glibc2.1 from
the ftp sites (actually I did but bzip2 always find errors), so I'm
running jdk1.2 for glibc2.0, seemingly without any other pb.


Thanks in advance for help.

Hicham Mouline
ManDrapeau Pte Ltd
69 Tras Street, Singapore 079008
mouline@etud.insa-tlse.fr