pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
JDBC Connection
19+ messages / 13 participants
[nested] [flat]

* JDBC Connection
@ 2001-11-08 20:14  Guido <lampo.14@iol.it>
  0 siblings, 3 replies; 19+ messages in thread

From: Guido @ 2001-11-08 20:14 UTC (permalink / raw)
  To: pgsql-jdbc

Hi everybody, here's my poroblem:

Distibution - RH 7.1
JDK - 1.3.1


I try to connect to the pgsql data base with my application but all I get
it's the following exception
	java.lang.ClassNotFoundException: org.postgresql.Driver
which is thrown by
	Class.forName("org.postgresql.Driver");

I followed the instructions on the Programmer's Guide by exporting

	/usr/java/jdk1.3.1_01/lib/jdbc7.1-1.2.jar (the dir where I've put
the jdbc driver)

to my PATH.
When I echo the PATH I get the correct sequence.

Thanks for all the help you can give me.

Guido




^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: JDBC Connection
@ 2001-11-09 03:55  Dave Cramer <Dave@micro-automation.net>
  parent: Guido <lampo.14@iol.it>
  2 siblings, 0 replies; 19+ messages in thread

From: Dave Cramer @ 2001-11-09 03:55 UTC (permalink / raw)
  To: 'Guido' <lampo.14@iol.it>; pgsql-jdbc

Guido,

Instead of adding it to PATH, you have to add it to an environment
variable CLASSPATH

Dave 

-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Guido
Sent: November 8, 2001 3:15 PM
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] JDBC Connection


Hi everybody, here's my poroblem:

Distibution - RH 7.1
JDK - 1.3.1


I try to connect to the pgsql data base with my application but all I
get
it's the following exception
	java.lang.ClassNotFoundException: org.postgresql.Driver
which is thrown by
	Class.forName("org.postgresql.Driver");

I followed the instructions on the Programmer's Guide by exporting

	/usr/java/jdk1.3.1_01/lib/jdbc7.1-1.2.jar (the dir where I've
put
the jdbc driver)

to my PATH.
When I echo the PATH I get the correct sequence.

Thanks for all the help you can give me.

Guido


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster





^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: JDBC Connection
@ 2001-11-09 11:28  Nick Fankhauser <nickf@ontko.com>
  parent: Guido <lampo.14@iol.it>
  2 siblings, 1 reply; 19+ messages in thread

From: Nick Fankhauser @ 2001-11-09 11:28 UTC (permalink / raw)
  To: Guido <lampo.14@iol.it>; pgsql-jdbc

Guido-

> to my PATH.

Are you using PATH or CLASSPATH? It should be CLASSPTH.

Also, make sure you are executing the class from the same environment that
has classpath set. Sometimes people will compile in one environment & then
execute in another (for instance compiling in your development account &
then running from the Tomcat user if you're running servlets.)

regards,

-Nick

--------------------------------------------------------------------------
Nick Fankhauser  nickf@ontko.com  Phone 1.765.935.4283  Fax 1.765.962.9788
Ray Ontko & Co.     Software Consulting Services     http://www.ontko.com/




^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: JDBC Connection
@ 2001-11-09 11:58  Nick Fankhauser <nickf@ontko.com>
  parent: Nick Fankhauser <nickf@ontko.com>
  0 siblings, 0 replies; 19+ messages in thread

From: Nick Fankhauser @ 2001-11-09 11:58 UTC (permalink / raw)
  To: nickf@ontko.com; Guido <lampo.14@iol.it>; pgsql-jdbc


 
> Are you using PATH or CLASSPATH? It should be CLASSPTH.
                                                 ^^^^^^
                                 oops! I meant CLASSPATH
                                          -NF

 



^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: JDBC Connection
@ 2001-11-09 16:41  Guido <lampo.14@iol.it>
  parent: Guido <lampo.14@iol.it>
  2 siblings, 2 replies; 19+ messages in thread

From: Guido @ 2001-11-09 16:41 UTC (permalink / raw)
  To: pgsql-jdbc

First of all I'd like to thank everybody for the "pronto" help.
But the problem is that
1. My shell doesn't have an enviroment variable called CLASSPATH;
2. I, then, tried to edit my .profile file, by adding the variable to it,
i.e.
	CLASSPATH=/usr/java/jdk1.3.1_01/lib/jdbc7.1-1.2.jar
	export PATH CLASSPATH
   but, still doesn't work.
3. When I run the application in the Forte 3 enviroment, it works
perfectly, but that becuase the IDE requires to copy the driver to the
IDE's directory.
4. I use the same enviroment for developing and running the application.
Thanks again.




^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: JDBC Connection
@ 2001-11-09 19:21  Dave Cramer <Dave@micro-automation.net>
  parent: Guido <lampo.14@iol.it>
  1 sibling, 0 replies; 19+ messages in thread

From: Dave Cramer @ 2001-11-09 19:21 UTC (permalink / raw)
  To: 'Guido' <lampo.14@iol.it>; pgsql-jdbc

Guido,

One way to get around the classpath issue is to put the jar into your
javahome/jre/lib/ext directory. By default all jars in this directory
will be accessible to your apps

So in your case there s/b a directory /usr/java/jdk1.3.1_01/jre/lib/ext

If you put the jar there it s/b available to your application

Dave 

-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Guido
Sent: November 9, 2001 11:42 AM
To: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] JDBC Connection


First of all I'd like to thank everybody for the "pronto" help.
But the problem is that
1. My shell doesn't have an enviroment variable called CLASSPATH;
2. I, then, tried to edit my .profile file, by adding the variable to
it,
i.e.
	CLASSPATH=/usr/java/jdk1.3.1_01/lib/jdbc7.1-1.2.jar
	export PATH CLASSPATH
   but, still doesn't work.
3. When I run the application in the Forte 3 enviroment, it works
perfectly, but that becuase the IDE requires to copy the driver to the
IDE's directory.
4. I use the same enviroment for developing and running the application.
Thanks again.


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)





^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: JDBC Connection
@ 2001-11-10 12:48  Nick Fankhauser <nickf@ontko.com>
  parent: Guido <lampo.14@iol.it>
  1 sibling, 1 reply; 19+ messages in thread

From: Nick Fankhauser @ 2001-11-10 12:48 UTC (permalink / raw)
  To: Guido <lampo.14@iol.it>; pgsql-jdbc

Guido-

I probably didn't say this clearly enough, or perhaps "environment" is the
wrong word, so I'll try to explain what I meant with an example:

In the project I'm working on, we're using Tomcat, so I develop using my
user account, but run as Tomcat's user.

When I'm actually writing & compiling the code, I'm working from my own user
account (nickf), so in the .profile for nickf I add the path to the jdbc jar
like so: "export CLASSPATH=$CLASSPATH:/usr/share/java/jdbc7.1-1.2.jar". This
works great for compiling and running any "main" test classes at the command
line, but my purpose is to produce code that Tomcat will run, and therein
lies the twist...

The Tomcat processes are started as detached processes by the "www-data"
user account on our system, so the change that I made to the CLASSPATH
environment variable for "nickf" doesn't help. In order to make the classes
work under this user, I have to do one of three things:

1)Add the classpath line that I used for "nickf" to the .profile for
"www-data"

2)Add the jar file to the classpath in the shell script that starts up
Tomcat

3)As Dave suggested, put it in the standard java extensions directory for
the system, so it is available to any user account by default.

I may be totally off base here, but it sounds very much like this is the
problem that is plaguing you with Forte- If a different user account is
running the code after you get it out of Forte, then you may lose the
CLASSPATH that you set.

The other thing that may be happening is that the CLASSPATH variable may not
be used by your JRE. It might help to look under the hood at the shell
script that invokes the JRE to see what is happening- the command to invoke
the JRE has a switch to set the classpath on it, and by convention, most
systems just equate this to CLASSPATH, but they don't have to. See if you
can locate the shell file (or .bat file) that invokes your JRE- it should
have a line that looks something like this:

java -cp $CLASSPATH <class file>

The problem of course, would be if the "CLASSPATH" variable either isn't
being used, or is being changed before this line is run. The only way I can
thin of to check this would be to find the shell script in question. Maybe
if you tell us what platform you're running on, someone who is familiar with
it can help.

Sorry- this response got rather long-winded- Hope it helps.

-Nick



> -----Original Message-----
> From: pgsql-jdbc-owner@postgresql.org
> [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Guido
> Sent: Friday, November 09, 2001 11:42 AM
> To: pgsql-jdbc@postgresql.org
> Subject: Re: [JDBC] JDBC Connection
>
>
> First of all I'd like to thank everybody for the "pronto" help.
> But the problem is that
> 1. My shell doesn't have an enviroment variable called CLASSPATH;
> 2. I, then, tried to edit my .profile file, by adding the variable to it,
> i.e.
> 	CLASSPATH=/usr/java/jdk1.3.1_01/lib/jdbc7.1-1.2.jar
> 	export PATH CLASSPATH
>    but, still doesn't work.
> 3. When I run the application in the Forte 3 enviroment, it works
> perfectly, but that becuase the IDE requires to copy the driver to the
> IDE's directory.
> 4. I use the same enviroment for developing and running the application.
> Thanks again.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>




^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: JDBC Connection
@ 2001-11-12 06:41  Max Larsson <max.larsson@gmservice.de>
  parent: Nick Fankhauser <nickf@ontko.com>
  0 siblings, 0 replies; 19+ messages in thread

From: Max Larsson @ 2001-11-12 06:41 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

if you want that Tomcat should find the jdbc jar you have two
places to it:

1.	$TOMCAT_HOME/lib or for TOMACT 4 $CATALINA_HOME/common/lib

or

2.	in your web application folder under WEB-INF/lib e.g if
	your web applictaion is anmed myapp :

	$TOMCAT_HOME/webapps/myapp/WEB-INF/lib or for Tomcat 4
	$CATALINA_HOME/webapps/myapp/WEB-INF/lib

HTH

Max

> -----Original Message-----
> From: pgsql-jdbc-owner@postgresql.org
> [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Nick Fankhauser
> Sent: Samstag, 10. November 2001 13:49
> To: Guido; pgsql-jdbc@postgresql.org
> Subject: Re: [JDBC] JDBC Connection
> 
> 
> Guido-
> 
> I probably didn't say this clearly enough, or perhaps 
> "environment" is the
> wrong word, so I'll try to explain what I meant with an example:
> 
> In the project I'm working on, we're using Tomcat, so I 
> develop using my
> user account, but run as Tomcat's user.
> 
> When I'm actually writing & compiling the code, I'm working 
> from my own user
> account (nickf), so in the .profile for nickf I add the path 
> to the jdbc jar
> like so: "export 
> CLASSPATH=$CLASSPATH:/usr/share/java/jdbc7.1-1.2.jar". This
> works great for compiling and running any "main" test classes 
> at the command
> line, but my purpose is to produce code that Tomcat will run, 
> and therein
> lies the twist...
> 
> The Tomcat processes are started as detached processes by the 
> "www-data"
> user account on our system, so the change that I made to the CLASSPATH
> environment variable for "nickf" doesn't help. In order to 
> make the classes
> work under this user, I have to do one of three things:
> 
> 1)Add the classpath line that I used for "nickf" to the .profile for
> "www-data"
> 
> 2)Add the jar file to the classpath in the shell script that starts up
> Tomcat
> 
> 3)As Dave suggested, put it in the standard java extensions 
> directory for
> the system, so it is available to any user account by default.
> 
> I may be totally off base here, but it sounds very much like 
> this is the
> problem that is plaguing you with Forte- If a different user 
> account is
> running the code after you get it out of Forte, then you may lose the
> CLASSPATH that you set.
> 
> The other thing that may be happening is that the CLASSPATH 
> variable may not
> be used by your JRE. It might help to look under the hood at the shell
> script that invokes the JRE to see what is happening- the 
> command to invoke
> the JRE has a switch to set the classpath on it, and by 
> convention, most
> systems just equate this to CLASSPATH, but they don't have 
> to. See if you
> can locate the shell file (or .bat file) that invokes your 
> JRE- it should
> have a line that looks something like this:
> 
> java -cp $CLASSPATH <class file>
> 
> The problem of course, would be if the "CLASSPATH" variable 
> either isn't
> being used, or is being changed before this line is run. The 
> only way I can
> thin of to check this would be to find the shell script in 
> question. Maybe
> if you tell us what platform you're running on, someone who 
> is familiar with
> it can help.
> 
> Sorry- this response got rather long-winded- Hope it helps.
> 
> -Nick
> 
> 
> 
> > -----Original Message-----
> > From: pgsql-jdbc-owner@postgresql.org
> > [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Guido
> > Sent: Friday, November 09, 2001 11:42 AM
> > To: pgsql-jdbc@postgresql.org
> > Subject: Re: [JDBC] JDBC Connection
> >
> >
> > First of all I'd like to thank everybody for the "pronto" help.
> > But the problem is that
> > 1. My shell doesn't have an enviroment variable called CLASSPATH;
> > 2. I, then, tried to edit my .profile file, by adding the 
> variable to it,
> > i.e.
> > 	CLASSPATH=/usr/java/jdk1.3.1_01/lib/jdbc7.1-1.2.jar
> > 	export PATH CLASSPATH
> >    but, still doesn't work.
> > 3. When I run the application in the Forte 3 enviroment, it works
> > perfectly, but that becuase the IDE requires to copy the 
> driver to the
> > IDE's directory.
> > 4. I use the same enviroment for developing and running the 
> application.
> > Thanks again.
> >
> >
> > ---------------------------(end of 
> broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister command
> >     (send "unregister YourEmailAddressHere" to 
> majordomo@postgresql.org)
> >
> 
> 
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://archives.postgresql.org



^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* jdbc connection
@ 2003-01-19 19:03  michel verplancke <michel.verplancke@wanadoo.be>
  0 siblings, 1 reply; 19+ messages in thread

From: michel verplancke @ 2003-01-19 19:03 UTC (permalink / raw)
  To: 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 String driver = "org.postgresql.Driver";
    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;
  }

int GetRecordnb() 
 {
     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;
 }

// alternative (donne le même résultat que la manière précédente)

// System.out.println(result.getFetchSize()); 

ResultSet GetRecordData() 
 {
 return result;
 }

void CloseConnection()
 {
  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

michel.verplancke@wanadoo.be
  

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* jdbc connection
@ 2003-01-19 19:46  michel verplancke <michel.verplancke@wanadoo.be>
  0 siblings, 2 replies; 19+ messages in thread

From: michel verplancke @ 2003-01-19 19:46 UTC (permalink / raw)
  To: 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 String driver = "org.postgresql.Driver";
    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;
  }

int GetRecordnb() 
 {
     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;
 }

// alternative (donne le même résultat que la manière précédente)

// System.out.println(result.getFetchSize()); 

ResultSet GetRecordData() 
 {
 return result;
 }

void CloseConnection()
 {
  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

michel.verplancke@wanadoo.be
  

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: jdbc connection
@ 2003-01-19 20:10  Abel Muiño <abel.muinho@mundo-r.com>
  parent: michel verplancke <michel.verplancke@wanadoo.be>
  1 sibling, 0 replies; 19+ messages in thread

From: Abel Muiño @ 2003-01-19 20:10 UTC (permalink / raw)
  To: michel verplancke <michel.verplancke@wanadoo.be>; +Cc: pgsql-jdbc

El dom, 19-01-2003 a las 20:46, michel verplancke escribió:
>  
> The error message is "connection is closed, operation is not
> permitted"
>  
	Most linux distributions ship PostgreSQL with remote access disabled.
Some even disable TCP/IP communication with the server.

	This is documented on the postgreSQL documentation.

	Check your /etc/postgresql/postgresql.conf (see if TCP/IP is enabled)
and /etc/postgresql/pg_hba.conf to see if access from your host is
allowed.
-- 
Abel Muiño Vizcaino




^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: jdbc connection
@ 2003-01-19 20:12  Paul Stead <pstead@elementallogic.com>
  parent: michel verplancke <michel.verplancke@wanadoo.be>
  1 sibling, 0 replies; 19+ messages in thread

From: Paul Stead @ 2003-01-19 20:12 UTC (permalink / raw)
  To: michel verplancke <michel.verplancke@wanadoo.be>; pgsql-jdbc

Just a real quick look, but it seems to me that you're closing your
connection before you use it....

      if( con != null)
       {
         try { con.close(); }                          You're closing it
here
         catch( Exception e2 ) {}
      }
    try
     {
  result = stmt.executeQuery(Valquery);           IT's HERE THAT I GET THE
PROBLEM !!!!!!!
     }

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: jdbc connection
@ 2003-01-24 19:00  Mykola Dudar <dmykola@ahpcc.unm.edu>
  parent: michel verplancke <michel.verplancke@wanadoo.be>
  0 siblings, 0 replies; 19+ messages in thread

From: Mykola Dudar @ 2003-01-24 19:00 UTC (permalink / raw)
  To: michel verplancke <michel.verplancke@wanadoo.be>; pgsql-jdbc

Thats my code - works perfectly on WXP.

import java.sql.*;

public class tst_jdbc 
{
  public static void start ()
       throws SQLException
  {
    // Load the JDBC driver
    DriverManager.registerDriver(new org.postgresql.Driver());

    String url = "jdbc:postgresql://COMPUTERNAME/DATABASENAME";
    String userName = "USERNAME";
    String password = "PASSWORD";

    Connection conn =
      DriverManager.getConnection (url, userName, password);

    // Create a Statement
    Statement stmt = conn.createStatement ();

    // Select the all rows
    ResultSet rset = stmt.executeQuery ("select * from TABLENAME"); 

    while (rset.next ())
      System.out.println (rset.getString (1));
  } // start();
  public static void main (String args [])
       throws SQLException
  {
    start ();
  }
}
  ----- Original Message ----- 
  From: michel verplancke 
  To: pgsql-jdbc@postgresql.org 
  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 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 String driver = "org.postgresql.Driver";
      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;
    }

  int GetRecordnb() 
   {
       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;
   }

  // alternative (donne le même résultat que la manière précédente)

  // System.out.println(result.getFetchSize()); 

  ResultSet GetRecordData() 
   {
   return result;
   }

  void CloseConnection()
   {
    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

  michel.verplancke@wanadoo.be
    

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* JDBC Connection
@ 2004-07-11 20:26  Eric Wright <eric.wright@shaw.ca>
  0 siblings, 1 reply; 19+ messages in thread

From: Eric Wright @ 2004-07-11 20:26 UTC (permalink / raw)
  To: pgsql-jdbc

Hello, 

I am having some trouble connecting to my postgres database. 
I have started off with a simple test class to make and test a connection. When I run the simple tester I am getting the following output:

    The connection failed.
    java.sql.SQLException: No suitable driver
     at java.sql.DriverManager.getConnection(DriverManager.java:532)
     at java.sql.DriverManager.getConnection(DriverManager.java:171)
     at app.dao.ConnectionTest.main(ConnectionTest.java:28)

From the following test class:

package app.dao;
import java.sql.*;

public class ConnectionTest {
 public static void main(String[] args) {
  String url    = "jdbc:postgres://192.168.1.101/asset";
  String user   = "asset$admin";
  String pwd    = "password";
  try {
   Class.forName("org.postgresql.Driver");
   Connection con = DriverManager.getConnection(url, user, pwd);
   if(!con.isClosed()){
    System.out.println("The connection succeeded");
    con.close();
   }
  }catch(Exception e){
   e.printStackTrace();
   System.out.println("The connection failed.");
  } 
 }
}


I have read the information at http://www.fankhausers.com/postgresql/jdbc/#nosuitabledriver
I am using Eclipse 3.0 and trying it run it in the debugger.
I am using postgresql 7.4, JDK 1.4, and pg74.214.jdbc3.jar

Any help that you can provide would be great. 

Thanks Eric W

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: JDBC Connection
@ 2004-07-12 01:54  Kris Jurka <books@ejurka.com>
  parent: Eric Wright <eric.wright@shaw.ca>
  0 siblings, 1 reply; 19+ messages in thread

From: Kris Jurka @ 2004-07-12 01:54 UTC (permalink / raw)
  To: Eric Wright <eric.wright@shaw.ca>; +Cc: pgsql-jdbc



On Sun, 11 Jul 2004, Eric Wright wrote:

> Hello, 
> 
> I am having some trouble connecting to my postgres database.  I have
> started off with a simple test class to make and test a connection. When
> I run the simple tester I am getting the following output:
> 
>     The connection failed.
>     java.sql.SQLException: No suitable driver
>   String url    = "jdbc:postgres://192.168.1.101/asset";

The URL must start with jdbc:postgresql not postgres.

Kris Jurka




^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: JDBC Connection
@ 2004-07-12 05:15  Eric Wright <eric.wright@shaw.ca>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 0 replies; 19+ messages in thread

From: Eric Wright @ 2004-07-12 05:15 UTC (permalink / raw)
  To: pgsql-jdbc

Thanks Kris,  my bad...

I will put on the pointy hat and sit in the corner until the end of class.

Eric


----- Original Message ----- 
From: "Kris Jurka" <books@ejurka.com>
To: "Eric Wright" <eric.wright@shaw.ca>
Cc: <pgsql-jdbc@postgresql.org>
Sent: Sunday, July 11, 2004 6:54 PM
Subject: Re: [JDBC] JDBC Connection


>
>
> On Sun, 11 Jul 2004, Eric Wright wrote:
>
> > Hello,
> >
> > I am having some trouble connecting to my postgres database.  I have
> > started off with a simple test class to make and test a connection. When
> > I run the simple tester I am getting the following output:
> >
> >     The connection failed.
> >     java.sql.SQLException: No suitable driver
> >   String url    = "jdbc:postgres://192.168.1.101/asset";
>
> The URL must start with jdbc:postgresql not postgres.
>
> Kris Jurka
>




^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* jdbc connection
@ 2007-05-31 09:16  N. Khodabakhsh <nadi2000@orange.nl>
  0 siblings, 2 replies; 19+ messages in thread

From: N. Khodabakhsh @ 2007-05-31 09:16 UTC (permalink / raw)
  To: pgsql-jdbc

Hello,

I have downloaded the postgresql 8.2 and wanted to make a connection with it. i get error like unknown source.
i send u herewith the source code (see attach). can you help me to fixe it?

Thank you,
Nico Khodabakhsh

Attachments:

  JDBC.doc (application/msword, 28.5K) download

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: jdbc connection
@ 2007-05-31 23:37  Guy Rouillier <guyr-ml1@burntmail.com>
  parent: N. Khodabakhsh <nadi2000@orange.nl>
  1 sibling, 0 replies; 19+ messages in thread

From: Guy Rouillier @ 2007-05-31 23:37 UTC (permalink / raw)
  To: pgsql-jdbc

N. Khodabakhsh wrote:
> Hello,
> 
> I have downloaded the postgresql 8.2 and wanted to make a connection 
> with it. i get error like unknown source.
> i send u herewith the source code (see attach). can you help me to fixe it?

You're question is rather generic, and you didn't provide a useful error 
message.  So helping is rather difficult.  What exact error are you 
receiving?  Your code looks okay.  Since you are specifying "localhost", 
is it safe to assume you are running this code on the same box running 
PostgreSQL?  Have you verified using psql that you can connect to the 
target database using the userid and password you have in this code?

-- 
Guy Rouillier



^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: jdbc connection
@ 2007-06-01 03:32  Mamoon Rashid <mamoon@imtech.res.in>
  parent: N. Khodabakhsh <nadi2000@orange.nl>
  1 sibling, 0 replies; 19+ messages in thread

From: Mamoon Rashid @ 2007-06-01 03:32 UTC (permalink / raw)
  To: pgsql-jdbc

hi nico,
please check your URL supplied during connection.you have given
URL= "jdbc:postgresql://localhost:5432/postgres"
1.you are assuming your database name as "postgres", plz check this should
be the actual name of your database.
If i am correct u supplied USERID = "postgres" and PASSWD= "showan2000".it
seems ok.
2. Do one more thing, replace localhost with [::1].
if all other things are ok your problem probably lies in connection.
Plz report me whether it worked or not.

mamoon



> Hello,
>
> I have downloaded the postgresql 8.2 and wanted to make a connection with
> it. i get error like unknown source.
> i send u herewith the source code (see attach). can you help me to fixe
> it?
>
> Thank you,
> Nico Khodabakhsh
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
>                 http://www.postgresql.org/about/donate
>




^ permalink  raw  reply  [nested|flat] 19+ messages in thread


end of thread, other threads:[~2007-06-01 03:32 UTC | newest]

Thread overview: 19+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-11-08 20:14 JDBC Connection Guido <lampo.14@iol.it>
2001-11-09 03:55 ` Dave Cramer <Dave@micro-automation.net>
2001-11-09 11:28 ` Nick Fankhauser <nickf@ontko.com>
2001-11-09 11:58   ` Nick Fankhauser <nickf@ontko.com>
2001-11-09 16:41 ` Guido <lampo.14@iol.it>
2001-11-09 19:21   ` Dave Cramer <Dave@micro-automation.net>
2001-11-10 12:48   ` Nick Fankhauser <nickf@ontko.com>
2001-11-12 06:41     ` Max Larsson <max.larsson@gmservice.de>
2003-01-19 19:03 jdbc connection michel verplancke <michel.verplancke@wanadoo.be>
2003-01-24 19:00 ` Re: jdbc connection Mykola Dudar <dmykola@ahpcc.unm.edu>
2003-01-19 19:46 jdbc connection michel verplancke <michel.verplancke@wanadoo.be>
2003-01-19 20:10 ` Re: jdbc connection Abel Muiño <abel.muinho@mundo-r.com>
2003-01-19 20:12 ` Re: jdbc connection Paul Stead <pstead@elementallogic.com>
2004-07-11 20:26 JDBC Connection Eric Wright <eric.wright@shaw.ca>
2004-07-12 01:54 ` Kris Jurka <books@ejurka.com>
2004-07-12 05:15   ` Eric Wright <eric.wright@shaw.ca>
2007-05-31 09:16 jdbc connection N. Khodabakhsh <nadi2000@orange.nl>
2007-05-31 23:37 ` Re: jdbc connection Guy Rouillier <guyr-ml1@burntmail.com>
2007-06-01 03:32 ` Re: jdbc connection Mamoon Rashid <mamoon@imtech.res.in>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox