Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Will Not Connect to PostgresQL on Mac

 
David Ellis Rogers
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running Eclipse Luna 2 (4.4.2) on Mac OS Yosemite (10.10.5).  The program was running (correctly collecting data from files), but then, after adding the JDBC to connect to PostgreSQL 9.4, it produced the following error:  "Error: No suitable driver found for jdbc:postgresql://localhost.pg1 "  I am trying to connect it to the PostgreSQL database for the first time on the Mac (was successful on PC but I'm a newbie on the Mac).  Had downloaded the JDBC from PostgreSQL site.

I think it is the CLASSPATH.  (On a Mac how does one insert the JDBC into the CLASSPATH?) I do not know how to find it on the Mac (probably something ridiculously simple).  Would greatly appreciate any and all help.
The attached show states of things.
Filename: Referenced-Libraries.tiff
Description:
File size: 240 Kbytes
[Download Referenced-Libraries.tiff] Download Attachment
 
David Ellis Rogers
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am adding attachments, which I did not know how to attach before.  Sorry.

I am running Eclipse Luna 2 (4.4.2) on Mac OS Yosemite (10.10.5).  The program was running (correctly collecting data from files), but then, after adding the JDBC to connect to PostgreSQL 9.4, it produced the following error:  "Error: No suitable driver found for jdbc:postgresql://localhost.pg1 "  I am trying to connect it to the PostgreSQL database for the first time on the Mac (was successful on PC but I'm a newbie on the Mac).  Had downloaded the JDBC from PostgreSQL site.

I think it is the CLASSPATH.  (On a Mac how appreciate any and all help.
The attached show states of things.
does one insert the JDBC into the CLASSPATH?) I do not know how to find it on the Mac (probably something ridiculously simple).  Would greatly appreciate help.

Please see attachments.

Filename: Pic-of-Package-Explorer.tiff
Description:
File size: 361 Kbytes
[Download Pic-of-Package-Explorer.tiff] Download Attachment
Filename: Pic-of-Error-Message.tiff
Description:
File size: 223 Kbytes
[Download Pic-of-Error-Message.tiff] Download Attachment
Filename: Build-Path.tiff
Description:
File size: 172 Kbytes
[Download Build-Path.tiff] Download Attachment
 
David Ellis Rogers
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code:
             
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you run the program?

If (on the Windows box) you set the global environment variable CLASSPATH then that would have been (IMO) an error of that setup.
The classpath should be defined local to the application, not to the box as a whole.
 
David Ellis Rogers
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I run the program from Eclipse,  Luna Service Release 2 (4.4.2).  I hit the green run button at the top.  It is on a Mac, not on Windows platform.  Please see attachments.
 
Tim Moores
Bartender
Posts: 3127
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jdbc:postgresql://localhost.pg1

That does not look like one of the recognized DB URL formats according to https://jdbc.postgresql.org/documentation/94/connect.html

As an aside, please don't post screenshots of text - copy/paste them here so that they are easily readable, can be easily quoted, and are searchable.

Also, I'm not familiar with Eclipse, but I note that you posted the build path containing the driver jar - the runtime path may be set elsewhere, and will also have to contain the jar.
 
David Ellis Rogers
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for noting the error.  I now have
String url ="jdbc:postgresql://localhost:5432/pg1"; // connect to DB
.

But I still get the same error.

When I press the run button, the first thing that happens is an error message occurs:  "Errors in Workspace" with the message box containing "Errors exist in required project".  It gives me the option to run or not.  So I tell it to continue.  Having made a simple change to the code, a println; it does not print the new line, simply does a previous run.  Seems it is not compiling correctly.

What do I do?
 
Knute Snortum
Bartender
Pie
Posts: 2878
62
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It gives me the option to run or not.  So I tell it to continue.

Don't do that.  The message is telling you there are problems in some classes in the project.  Correct the problems first.

In Eclipse, there will be a red "x" net to the line with the problem and a squiggly line under where in the line it thinks the problem starts.  In Netbeans it's similar, but it's a lightbulb with a little red exclamation mark.
 
David Ellis Rogers
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have looked at all the classes, there are no error marks.

I have also looked at the Referenced Libraries.  I click on the classes under the postgresql-9.4-1200.jdbc4.jar and they all say that the source attachment does not contain the source for the file X.class (e.g., Driver.class, PGConnection.class).

I suspect that I should download the JDBC from PostgreSQL and restart (?).

Knute, thanks for your help.
 
Knute Snortum
Bartender
Pie
Posts: 2878
62
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell us if that helped.  The current version is 1211, so 1200 is a little behind.  Still, I would except that it would have Driver.class in it!
 
David Ellis Rogers
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have resolved the problem by doing the following.  Note:  this is on a Mac OS X Yosemite 10.10.5, using Eclipse (Version: Luna Service Release 2 (4.4.2)).

1. Deleted old postgesql downloads in download folder.
2. Downloaded from https://jdbc.postgresql.org the appropriate driver for my JVM of 1.8.
3. Copied the following files from the download to the project.src.lib folder
  • Postgresql-jdbc-head.doc
  • Postgresql-9.4.12.11.jar
  • Postgresql-jdbc-head.doc.tar

  • (Note: believe only the jar is necessary, but above doesn’t hurt)
    4. In Project Explorer
  • go to project 
  • Referenced Libraries, right click
  • Select Build Path, select Configure Build Plan
  • Select Libraries tab
  • Remove old postgresql entries (which had no entries in them)
  • Select add JARS
  • Open project.
  • Select src.lib
  • Highlight material there.
  • Click OK, OK.


  •  
    Knute Snortum
    Bartender
    Pie
    Posts: 2878
    62
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for posting the solution!  Have a cow! (that's a good thing)
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic