jdbc connection - Mailing list pgsql-jdbc
| From | michel verplancke | 
|---|---|
| Subject | jdbc connection | 
| Date | |
| Msg-id | 002901c2bff3$75158d20$010210ac@principalb Whole thread Raw  | 
		
| Responses | 
                	
            		Re: jdbc connection
            		
            		 Re: jdbc connection  | 
		
| List | pgsql-jdbc | 
Please can you help me
I try to connect a java application from a windows W2K to a Linux postgresql 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.*;
 
public class JdbcQuery {
private Connection con = null;
public int recordnb = 0;
private Statement stmt = null;
private ResultSet result = null;
private Connection con = null;
public int recordnb = 0;
private Statement stmt = null;
private ResultSet result = null;
    private String driver = "org.postgresql.Driver";
private String url = "jdbc:postgresql://COMPUTERNAME:5432/DATABASE";
private String username = "michels";
private String password = "";
private String url = "jdbc:postgresql://COMPUTERNAME:5432/DATABASE";
private String username = "michels";
private String password = "";
boolean ConnectPostgresql(String Valquery) { 
try // Attempt to load the JDBC driver
{
Class.forName(driver);
}
catch( Exception e ) // error
{
JOptionPane.showMessageDialog(null, "Failed to load the following JDBC driver : " + e.getMessage(), "Error ! ", JOptionPane.PLAIN_MESSAGE);
return false;
}
try
{
con = DriverManager.getConnection ( url, username, password);
stmt = con.createStatement();
}
catch ( Exception e)
{
JOptionPane.showMessageDialog(null, "Problems connecting to " + url + ":" + e.getMessage(), "Error ! ", JOptionPane.PLAIN_MESSAGE);
return false;
}
if( con != null)
{
try { con.close(); }
catch( Exception e2 ) {}
}
try
{
result = stmt.executeQuery(Valquery); IT's HERE THAT I GET THE PROBLEM !!!!!!!
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "Problems with resultset : " + e.getMessage(), "Error ! ", JOptionPane.PLAIN_MESSAGE);
return false;
}
return true;
}
try // Attempt to load the JDBC driver
{
Class.forName(driver);
}
catch( Exception e ) // error
{
JOptionPane.showMessageDialog(null, "Failed to load the following JDBC driver : " + e.getMessage(), "Error ! ", JOptionPane.PLAIN_MESSAGE);
return false;
}
try
{
con = DriverManager.getConnection ( url, username, password);
stmt = con.createStatement();
}
catch ( Exception e)
{
JOptionPane.showMessageDialog(null, "Problems connecting to " + url + ":" + e.getMessage(), "Error ! ", JOptionPane.PLAIN_MESSAGE);
return false;
}
if( con != null)
{
try { con.close(); }
catch( Exception e2 ) {}
}
try
{
result = stmt.executeQuery(Valquery); IT's HERE THAT I GET THE PROBLEM !!!!!!!
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "Problems with resultset : " + e.getMessage(), "Error ! ", JOptionPane.PLAIN_MESSAGE);
return false;
}
return true;
}
int GetRecordnb() 
{
try
{
result.last();
recordnb = result.getRow();
result.beforeFirst();
{
try
{
result.last();
recordnb = result.getRow();
result.beforeFirst();
     } // end try
catch ( Exception e)
{
System.err.println( "problems in GetRecordnb managing resultset" );
System.err.println( e.getMessage() );
if( con != null)
{
try { con.close(); }
catch( Exception e2 ) {}
}
} // end catch
return recordnb;
}
catch ( Exception e)
{
System.err.println( "problems in GetRecordnb managing resultset" );
System.err.println( e.getMessage() );
if( con != null)
{
try { con.close(); }
catch( Exception e2 ) {}
}
} // end catch
return recordnb;
}
// alternative (donne le même résultat que la manière précédente)
// System.out.println(result.getFetchSize()); 
ResultSet GetRecordData() 
{
return result;
}
{
return result;
}
void CloseConnection()
{
try { stmt.close(); }
catch( Exception e ) {}
try { con.close(); }
catch( Exception e ) {}
}
{
try { stmt.close(); }
catch( Exception e ) {}
try { con.close(); }
catch( Exception e ) {}
}
} // end class 
If I try the same query from the Cygwin psql it works !!
Does somebody have an idea ?
Thanks
pgsql-jdbc by date: