pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amn Ojee Uw <amnojeeuw@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: My 1st JDBC and PostgreSQL
Date: Wed, 19 Jul 2023 20:37:07 -0400
Message-ID: <b7689ed5-773b-03ad-5f8c-5f18c97bafc3@gmail.com> (raw)

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?


Any help would be much appreciated.






view thread (7+ messages)  latest in thread

Message-ID: <b7689ed5-773b-03ad-5f8c-5f18c97bafc3@gmail.com>
Permalink:  ../b7689ed5-773b-03ad-5f8c-5f18c97bafc3@gmail.com/
Also on:    postgresql.org/message-id/b7689ed5-773b-03ad-5f8c-5f18c97bafc3@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: amnojeeuw@gmail.com
  Subject: Re: My 1st JDBC and PostgreSQL
  In-Reply-To: <b7689ed5-773b-03ad-5f8c-5f18c97bafc3@gmail.com>
  References: <b7689ed5-773b-03ad-5f8c-5f18c97bafc3@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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