1
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;


class Demopsql{

Demopsql()
{
    try {
        Class.forName("org.postgresql.Driver");
    } catch (ClassNotFoundException e) {
        System.out.println("Where is your PostgreSQL JDBC Driver? "
                    + "Include in your library path!");
            e.printStackTrace();
            return;    
    }    
}

where should it be paste postgresql-42.1.4.jar or extracted at where?

so that program won't throw class not found exception.

zaerymoghaddam
  • 3,037
  • 1
  • 27
  • 33
noeg
  • 11
  • 3

2 Answers2

0

If you are using eclipse, you can follow the method which is written on this post: Import Libraries in Eclipse? You will have to put it as an "external jar".

Or you can look at the maven project possibility: https://maven.apache.org/ You will just have to create a maven project and put a dependency into a file (pom.xml). It will be downloaded when you will do a maven update operation on your project. I give you the text which should be added to the pom.xml file:

<dependency>
   <groupId>org.postgresql</groupId>
   <artifactId>postgresql</artifactId>
   <version>42.1.4</version>
</dependency>
0

If you are using a build tool like maven, add this jar as a dependency. Otherwise you have to make sure that this jar is accessible in classpath. In Eclipse go to project properties -> build path -> Libraries tab , you can find a button to Add External JARs. Add this JAR as external jar.

Eldhose Abraham
  • 551
  • 3
  • 8
  • @EldhoseAbrahami am not using any ide just linux terminal – noeg Nov 17 '17 at 13:06
  • make sure this is accessible in classpath. https://stackoverflow.com/questions/9200334/how-to-compile-java-project-with-external-jar-file-in-linux-terminal should help. – Eldhose Abraham Nov 17 '17 at 13:10