pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Ver. 12.1 successfully installed on Win 10 but having trouble with jdbc jar
2+ messages / 2 participants
[nested] [flat]

* Ver. 12.1 successfully installed on Win 10 but having trouble with jdbc jar
@ 2020-01-20 00:24  CR20 <mez283em23e2ze2@yahoo.com>
  0 siblings, 1 reply; 2+ messages in thread

From: CR20 @ 2020-01-20 00:24 UTC (permalink / raw)
  To: pgsql-admin@lists.postgresql.org

Hi,

I have postgresql-12.1-3-windows-x64 installed and apparently working, 
but I'm then I'm trying a simple Java connection example as follows:

import java.sql.*;

public class CreateTable {
     public static void main(String args[]) {
         Connection c = null;
         Statement stmt = null;
         String CreateSql = null;

         try {
             Class.forName("org.postgresql.Driver");
             c = 
DriverManager.getConnection("jdbc:postgresql://localhost:5432/procedure_demo", 
"postgres", "adminedb");
             System.out.println("Database Connected ..");
             stmt = c.createStatement();
             CreateSql = "Create Table Test(id int primary key, name 
varchar, address text) ";
             stmt.executeUpdate(CreateSql);
             stmt.close();
             c.close();
         }

         catch (Exception e) {
             System.err.println( e.getClass().getName()+": "+ 
e.getMessage() );
             System.exit(0);
         }

         System.out.println("Table Created successfully");
     }
}

...which compiled successfully but when I go to run it, with 
postgresql-42.2.9.jar stored in path C:\PostgreSQL\libs, like as follows:

java -cp C:\PostgreSQL\libs . CreateTable

...the command line returns:

Error: Could not find or load main class .

Some of this is my limited knowledge of Java.  My question then is, 
Where should the jdbc jar be located in order to run, and then how do I 
run all this at the command line?  Thank you for any help.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Ver. 12.1 successfully installed on Win 10 but having trouble with jdbc jar
@ 2020-01-20 09:13  Laurenz Albe <laurenz.albe@cybertec.at>
  parent: CR20 <mez283em23e2ze2@yahoo.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Laurenz Albe @ 2020-01-20 09:13 UTC (permalink / raw)
  To: CR20 <mez283em23e2ze2@yahoo.com>; pgsql-admin@lists.postgresql.org

On Sun, 2020-01-19 at 19:24 -0500, CR20 wrote:
> ...which compiled successfully but when I go to run it, with postgresql-42.2.9.jar stored in path C:\PostgreSQL\libs, like as follows:
> 
> java -cp C:\PostgreSQL\libs . CreateTable
> 
> ...the command line returns:
> 
> Error: Could not find or load main class .
> 
> Some of this is my limited knowledge of Java.

Indeed.  You have to treat the JAR file as if it were a directory,
that is, put the file itself on the class path:

  java -cp C:\PostgreSQL\libs\postgresql-42.2.9.jar;. CreateTable

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2020-01-20 09:13 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-01-20 00:24 Ver. 12.1 successfully installed on Win 10 but having trouble with jdbc jar CR20 <mez283em23e2ze2@yahoo.com>
2020-01-20 09:13 ` Laurenz Albe <laurenz.albe@cybertec.at>

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