Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 0959C47613F for ; Fri, 24 Jan 2003 14:41:15 -0500 (EST) Received: from nfserver.ahpcc.unm.edu (mailhost.ahpcc.unm.edu [129.24.245.111]) by postgresql.org (Postfix) with ESMTP id EFC734761B0 for ; Fri, 24 Jan 2003 14:00:27 -0500 (EST) Received: from MINIME (minime.ahpcc.unm.edu [129.24.244.168]) by nfserver.ahpcc.unm.edu (8.9.3/8.9.3/Debian 8.9.3-21) with SMTP id MAA32043; Fri, 24 Jan 2003 12:00:23 -0700 X-Authentication-Warning: nfserver.ahpcc.unm.edu: Host minime.ahpcc.unm.edu [129.24.244.168] claimed to be MINIME Message-ID: <001901c2c3da$dc8cff70$a8f41881@MINIME> From: "Mykola Dudar" To: "michel verplancke" , References: <000801c2bfed$76d489f0$010210ac@principalb> Subject: Re: jdbc connection Date: Fri, 24 Jan 2003 12:00:28 -0700 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0016_01C2C3A0.2FD38450" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/291 X-Sequence-Number: 6141 This is a multi-part message in MIME format. ------=_NextPart_000_0016_01C2C3A0.2FD38450 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thats my code - works perfectly on WXP. import java.sql.*; public class tst_jdbc=20 { public static void start () throws SQLException { // Load the JDBC driver DriverManager.registerDriver(new org.postgresql.Driver()); String url =3D "jdbc:postgresql://COMPUTERNAME/DATABASENAME"; String userName =3D "USERNAME"; String password =3D "PASSWORD"; Connection conn =3D DriverManager.getConnection (url, userName, password); // Create a Statement Statement stmt =3D conn.createStatement (); // Select the all rows ResultSet rset =3D stmt.executeQuery ("select * from TABLENAME");=20 while (rset.next ()) System.out.println (rset.getString (1)); } // start(); public static void main (String args []) throws SQLException { start (); } } ----- Original Message -----=20 From: michel verplancke=20 To: pgsql-jdbc@postgresql.org=20 Sent: Sunday, January 19, 2003 12:03 PM Subject: [JDBC] jdbc connection Please can you help me I try to connect a java application from a windows W2K to a Linux postgre= sql with a very simple query, which is "select * from table". The error message is "connection is closed, operation is not permitted" here is the class definition import java.sql.*; =20=20=20 public class JdbcQuery { private Connection con =3D null; public int recordnb =3D 0; private Statement stmt =3D null; private ResultSet result =3D null; private String driver =3D "org.postgresql.Driver"; private String url =3D "jdbc:postgresql://COMPUTERNAME:5432/DATABASE"; private String username =3D "michels"; private String password =3D ""; boolean ConnectPostgresql(String Valquery) {=20 try // Attempt to load the JDBC driver {=20=20=20=20=20 Class.forName(driver); }=20 catch( Exception e ) // error { JOptionPane.showMessageDialog(null, "Failed to load the following JDBC = driver : " + e.getMessage(), "Error ! ", JOptionPane.PLAIN_MESSAGE); return false; }=20 try { con =3D DriverManager.getConnection ( url, username, password); stmt =3D con.createStatement(); } catch ( Exception e) { JOptionPane.showMessageDialog(null, "Problems connecting to " + url + = ":" + e.getMessage(), "Error ! ", JOptionPane.PLAIN_MESSAGE); return false; } if( con !=3D null) { try { con.close(); } catch( Exception e2 ) {} }=20 try { result =3D stmt.executeQuery(Valquery); IT's HERE THAT I GET = THE PROBLEM !!!!!!! }=20 catch (Exception e)=20=20 { JOptionPane.showMessageDialog(null, "Problems with resultset : " + e.g= etMessage(), "Error ! ", JOptionPane.PLAIN_MESSAGE); return false; } return true; } int GetRecordnb()=20 { try { result.last(); recordnb =3D result.getRow(); result.beforeFirst(); } // end try catch ( Exception e) { System.err.println( "problems in GetRecordnb managing resultset" = ); System.err.println( e.getMessage() ); if( con !=3D null) { try { con.close(); } catch( Exception e2 ) {} }=20 } // end catch=20 return recordnb; } // alternative (donne le m=EAme r=E9sultat que la mani=E8re pr=E9c=E9dent= e) // System.out.println(result.getFetchSize());=20 ResultSet GetRecordData()=20 { return result; } void CloseConnection() { try { stmt.close(); } catch( Exception e ) {} try { con.close(); } catch( Exception e ) {} }=20 } // end class=20 If I try the same query from the Cygwin psql it works !! Does somebody have an idea ? Thanks michel.verplancke@wanadoo.be =20=20=20=20 ------=_NextPart_000_0016_01C2C3A0.2FD38450 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Thats my code - works perfectly on = WXP.
 
import java.sql.*;
 
public class tst_jdbc
{
  publ= ic static=20 void start ()
       throws=20 SQLException
  {
    // Load the JDBC=20 driver
    DriverManager.registerDriver(new=20 org.postgresql.Driver());
 
    String url =3D=20 "jdbc:postgresql://COMPUTERNAME/DATABASENAME";
    String= =20 userName =3D "USERNAME";
    String password =3D=20 "PASSWORD";
 
    Connection conn=20 =3D
      DriverManager.getConnection (url, use= rName,=20 password);
 
    // Create a=20 Statement
    Statement stmt =3D conn.createStatement=20 ();
 
    // Select the all= =20 rows
    ResultSet rset =3D=20 stmt.executeQuery ("select * from TABLENAME");
 
    while (rset.next=20 ())
      System.out.println (rset.getString=20 (1));
  } // start();
  public static void main (String arg= s=20 [])
       throws SQLException
 = =20 {
    start ();
&nb= sp;=20 }
}
----- Original Message -----
Fro= m:=20 michel verplancke
To: pgsql-jdbc@postgresql.org <= /DIV>
Sent: Sunday, January 19, 2003 12:= 03=20 PM
Subject: [JDBC] jdbc connection

Please can you help me
 
I try to connect a java application from= a=20 windows W2K to a Linux postgresql with a very simple query, which is= =20 "select * from table".
 
The error message is "connection is= closed,=20 operation is not permitted"
 
here is the class definition=
 
 import java.sql.*;
<= FONT=20 face=3DArial size=3D2> 
public class JdbcQuery=20 {
    private Connection con =3D null;
  &= nbsp;=20 public int recordnb =3D 0;
    private Statement stmt = =3D=20 null;
    private ResultSet result =3D null;
 
    private String dr= iver =3D=20 "org.postgresql.Driver";
    private String url =3D=20 "jdbc:postgresql://COMPUTERNAME:5432/DATABASE";
    pri= vate=20 String username =3D "michels";
    private String passw= ord =3D=20 "";
 
boolean ConnectPostgresql(String Val= query)=20 { 
 try   // Attempt to load the JDBC=20 driver
   =20  {     
     Cl= ass.forName(driver);
  =20   } 
    catch( Exception e )  //= =20 error
   =20  {
  JOptionPane.showMessageDialog(null, "Failed to loa= d the=20 following JDBC driver : " + e.getMessage(), "Error ! ",=20 JOptionPane.PLAIN_MESSAGE);
  return=20 false;
      }
   =20 try
     {
  con =3D=20 DriverManager.getConnection ( url, username, password);
  st= mt =3D=20 con.createStatement();
     }
  =20  catch ( Exception e)
   =20  {
   JOptionPane.showMessageDialog(null, "Problem= s=20 connecting to " + url + ":" + e.getMessage(), "Error ! ",=20 JOptionPane.PLAIN_MESSAGE);
  return=20 false;
   }
      if( con != =3D=20 null)
     =20  {
         try { con.clo= se();=20 }
         catch( Exception e2= )=20 {}
      }
  =20  try
     {
  result =3D=20 stmt.executeQuery(Valquery);       &nb= sp;   IT's HERE THAT I GET THE PROBLEM=20 !!!!!!!
     }
  &nb= sp;=20 catch (Exception e) =20
  {
   JOptionPane.showMessageDialog(null= ,=20 "Problems with resultset : " + e.getMessage(), "Error ! ",=20 JOptionPane.PLAIN_MESSAGE);
  return=20 false;
  }
 return=20 true;
  }
 
int GetRecordnb()=20
 {
     try
   =20  {
  result.last();
  recordnb =3D=20 result.getRow();
  result.beforeFirst();
 
     } // end=20 try
    catch ( Exception e)
   =20  {
        System.err.println(= =20 "problems in GetRecordnb managing resultset"=20 );
        System.err.println(=20 e.getMessage() );
      if( con !=3D=20 null)
     =20  {
         try { con.clo= se();=20 }
         catch( Exception e2= )=20 {}
      }
     } // = end=20 catch 
  return recordnb;
 }
 
// alternative (donne le m=EAme r=E9= sultat que la=20 mani=E8re pr=E9c=E9dente)
 
// System.out.println(result.getFetchSize()); 
 
ResultSet GetRecordData()=20
 {
 return result;
 }
 
void=20 CloseConnection()
 {
  try { stmt.close();=20 }
        catch( Exception e )=20 {}
        try { con.close();=20 }
        catch( Exception e )=20 {}
       }
 
} // end class
 
If I try the same query from the Cygwin = psql it=20 works !!
 
Does somebody have an idea ?
 
Thanks
 
michel.verplancke@wanadoo.be=
  
 
<= /HTML> ------=_NextPart_000_0016_01C2C3A0.2FD38450--