Re: My 1st JDBC and PostgreSQL - Mailing list pgsql-general

From Jeffrey Walton
Subject Re: My 1st JDBC and PostgreSQL
Date
Msg-id CAH8yC8n4BNM8fiA68veroivKYY4TBf4uj5tr_BpCcB95ewGYEA@mail.gmail.com
Whole thread Raw
In response to My 1st JDBC and PostgreSQL  (Amn Ojee Uw <amnojeeuw@gmail.com>)
List pgsql-general
On Wed, Jul 19, 2023 at 8:37 PM Amn Ojee Uw <amnojeeuw@gmail.com> wrote:
>
> Following the example in :
> https://www.tutorialspoint.com/postgresql/postgresql_java.htm
> I wrote the bellow method :
>
> public void connectToDatabase() throws ClassNotFoundException,
> SQLException {
>          try {
>              this.perr(this.getDatabaseClass()); //
> org.postgresql.Driver = Class
>              this.perr(this.getDatabaseUrl());   //
> jdbc:postgresql://localhost:5432/sara.pgdb = url
>              this.perr(this.getUserID());        // chispa = user
>              this.perr(this.getUserPassword());  // 8UUKZW = password
>
>              Class.forName(this.getDatabaseClass().toString());
>              conn =
> DriverManager.getConnection(this.getDatabaseUrl().toString(),
>                      this.getUserID().toString(),
>                      this.getUserPassword().toString() );
>          } catch (final SQLException | ClassNotFoundException e) {
>              throw e;
>          }
>      }
>
> However, it throws an exception that reads :
> Exception in thread "main" org.postgresql.util.PSQLException: FATAL:
> database "sara.pgdb" does not exist
>
> In reference to the above web page, it reads :
> The following Java code shows how to connect to an existing database. If
> the database does not exist, then it will be created and finally a
> database object will be returned.
>
> True, the database file does not exist, but isn't JDBC supposed to
> create it?

If you are not married to tutorialspoint.com gear, then you can get
the Chinook database for testing. Chinook is the free/open source
alternative to Microsoft's Northwind database. See
https://github.com/lerocha/chinook-database .

Jeff



pgsql-general by date:

Previous
From: Chuck Davis
Date:
Subject: Re: My 1st JDBC and PostgreSQL
Next
From: Anthony Apollis
Date:
Subject: Postgres SQL