pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedMy 1st JDBC and PostgreSQL
7+ messages / 5 participants
[nested] [flat]
* My 1st JDBC and PostgreSQL
@ 2023-07-20 00:37 Amn Ojee Uw <amnojeeuw@gmail.com>
0 siblings, 4 replies; 7+ messages in thread
From: Amn Ojee Uw @ 2023-07-20 00:37 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
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.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: My 1st JDBC and PostgreSQL
@ 2023-07-20 00:58 Tom Lane <tgl@sss.pgh.pa.us>
parent: Amn Ojee Uw <amnojeeuw@gmail.com>
3 siblings, 0 replies; 7+ messages in thread
From: Tom Lane @ 2023-07-20 00:58 UTC (permalink / raw)
To: Amn Ojee Uw <amnojeeuw@gmail.com>; +Cc: pgsql-general@lists.postgresql.org
Amn Ojee Uw <amnojeeuw@gmail.com> writes:
> https://www.tutorialspoint.com/postgresql/postgresql_java.htm
> 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?
I think that web page is lying to you. JDBC cannot promise to
create a database for you, because (a) if the given database
doesn't exist, it would have to guess at some other database
to connect to, with no certainty of success; and (b) even if
it manages to connect to the server, there's no certainty
that you'd have permissions to create a new database.
So I don't believe any JDBC driver would even try.
regards, tom lane
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: My 1st JDBC and PostgreSQL
@ 2023-07-20 01:11 Chuck Davis <cjgunzel@gmail.com>
parent: Amn Ojee Uw <amnojeeuw@gmail.com>
3 siblings, 1 reply; 7+ messages in thread
From: Chuck Davis @ 2023-07-20 01:11 UTC (permalink / raw)
To: ; +Cc: pgsql-general@lists.postgresql.org
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@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?
>
>
> Any help would be much appreciated.
>
>
>
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: My 1st JDBC and PostgreSQL
@ 2023-07-20 01:52 Jeffrey Walton <noloader@gmail.com>
parent: Amn Ojee Uw <amnojeeuw@gmail.com>
3 siblings, 0 replies; 7+ messages in thread
From: Jeffrey Walton @ 2023-07-20 01:52 UTC (permalink / raw)
To: Amn Ojee Uw <amnojeeuw@gmail.com>; +Cc: pgsql-general@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: My 1st JDBC and PostgreSQL
@ 2023-07-20 15:18 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Chuck Davis <cjgunzel@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Adrian Klaver @ 2023-07-20 15:18 UTC (permalink / raw)
To: Chuck Davis <cjgunzel@gmail.com>; +Cc: pgsql-general@lists.postgresql.org
On 7/19/23 18:11, Chuck Davis wrote:
> 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".
Not sure what "you get what you pay for" means in this context?
My take is you are differentiating between embedded databases such as
Derby and SQLite which are tied to a specific client and client/server
databases like Postgres and MySQL which stand alone and are connected to
by any number of clients.
> 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.
>
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: My 1st JDBC and PostgreSQL
@ 2023-07-20 15:21 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Amn Ojee Uw <amnojeeuw@gmail.com>
3 siblings, 0 replies; 7+ messages in thread
From: Adrian Klaver @ 2023-07-20 15:21 UTC (permalink / raw)
To: Amn Ojee Uw <amnojeeuw@gmail.com>; pgsql-general@lists.postgresql.org
On 7/19/23 17:37, Amn Ojee Uw wrote:
> Following the example in :
> https://www.tutorialspoint.com/postgresql/postgresql_java.htm
Avoid the site above it will lead you down many false paths.
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: My 1st JDBC and PostgreSQL
@ 2023-07-20 16:44 Chuck Davis <cjgunzel@gmail.com>
parent: Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 0 replies; 7+ messages in thread
From: Chuck Davis @ 2023-07-20 16:44 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general@lists.postgresql.org
You get the value you're willing to work for as a general rule. It takes
more effort to admin a real SQL server than an easy embedded DB. Your
interpretation is spot on.
On Thu, Jul 20, 2023 at 8:18 AM Adrian Klaver <adrian.klaver@aklaver.com>
wrote:
> On 7/19/23 18:11, Chuck Davis wrote:
> > 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".
>
> Not sure what "you get what you pay for" means in this context?
>
> My take is you are differentiating between embedded databases such as
> Derby and SQLite which are tied to a specific client and client/server
> databases like Postgres and MySQL which stand alone and are connected to
> by any number of clients.
>
> > 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.
> >
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
>
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2023-07-20 16:44 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-07-20 00:37 My 1st JDBC and PostgreSQL Amn Ojee Uw <amnojeeuw@gmail.com>
2023-07-20 00:58 ` Tom Lane <tgl@sss.pgh.pa.us>
2023-07-20 01:11 ` Chuck Davis <cjgunzel@gmail.com>
2023-07-20 15:18 ` Adrian Klaver <adrian.klaver@aklaver.com>
2023-07-20 16:44 ` Chuck Davis <cjgunzel@gmail.com>
2023-07-20 01:52 ` Jeffrey Walton <noloader@gmail.com>
2023-07-20 15:21 ` Adrian Klaver <adrian.klaver@aklaver.com>
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