Re: My 1st JDBC and PostgreSQL

From: Chuck Davis <cjgunzel(at)gmail(dot)com>
To:
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: My 1st JDBC and PostgreSQL
Date: 2023-07-20 01:11:44
Message-ID: CAHf=Y_aDh9NXoPCRAdCKCJeRa8Qn7+YPR8Q+GRxwDE1eMr7OPA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Postgresql is a sophisticated database server. You can do what you're
attempting with something like Derby at the connection. But with
Postgresql "you get what you pay for".
1) Insall Postgresql
2) start the database
3) use the interface app psql to create a database;
4) load the JDBC driver in your client and connect.
5) manipulate the database via the JDBC driver.

All these steps are explained quite nicely in the Postgresql documentation
you can find at the web site. The JDBC site is separate but a Google
search will find it for you.

On Wed, Jul 19, 2023 at 5:37 PM Amn Ojee Uw <amnojeeuw(at)gmail(dot)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?
>
>
> Any help would be much appreciated.
>
>
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeffrey Walton 2023-07-20 01:52:04 Re: My 1st JDBC and PostgreSQL
Previous Message Tom Lane 2023-07-20 00:58:48 Re: My 1st JDBC and PostgreSQL