pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Franco Bruno Borghesi <franco@akyasociados.com.ar>
To: Greg Lugering <glugering@cfl.rr.com>
To: pgsql-admin@postgresql.org
Subject: Re: JDBC Drivers for Java
Date: Mon, 14 Apr 2003 13:56:11 -0300
Message-ID: <200304141356.11542.franco@akyasociados.com.ar> (raw)
In-Reply-To: <000801c30084$c5dd65d0$ef00a8c0@cfl.rr.com>
References: <000801c30084$c5dd65d0$ef00a8c0@cfl.rr.com>

Here is working example for you to try:

--In my databse
CREATE TABLE people (
   id SERIAL,
   name TEXT
);
INSERT INTO people(name) VALUES ('sue');
INSERT INTO people(name) VALUES ('peter');
INSERT INTO people(name) VALUES ('tony');
INSERT INTO people(name) VALUES ('mary');
 

--ListPeople.java
import java.sql.*;

public class ListPeople {
   public static void main(String[] args) {   
      try {
         Class.forName("org.postgresql.Driver");
         
         //the url is 
jdbc:postgresql://<host_name>:<port_number>/<database_name>?user=<user_name>&password=<password>
         //in my case, the database is in localhost, and I need no passwords, 
so using 
         //jdbc:postgresql:<database_name>?user=<user_name> will be just fine
         Connection 
con=DriverManager.getConnection("jdbc:postgresql:franco?user=admin");
         Statement stmt=con.createStatement();
         ResultSet rs=stmt.executeQuery("SELECT * FROM people");
         while (rs.next()) {
            System.out.println(rs.getString("name"));
         }
      }
      catch (Exception e) {
         System.out.println("Exception: "+e.getMessage());
      }
   }
}

It works for me, so if doesn't work for you I'm sure the problem is in your 
CLASSPATH.

On Friday 11 April 2003 20:47, Greg Lugering wrote:
> I just installed the Windows version of PostgreSQL 7.3.1.
> A jar file was included however the path was org/postgresql/Driver which
> causes and exception. I expected somethig like org.postgresql.Driver.
>
> If anyone can help me and send the exact code for making the connection it
> woud be appreciated.
>
> Thanks!
>
> Bob Lugering
> blugering@cfl.rr.com

view thread (2+ messages)

Message-ID: <200304141356.11542.franco@akyasociados.com.ar>
Permalink:  ../200304141356.11542.franco@akyasociados.com.ar/
Also on:    postgresql.org/message-id/200304141356.11542.franco@akyasociados.com.ar

 · 

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-admin@postgresql.org
  Cc: franco@akyasociados.com.ar, glugering@cfl.rr.com
  Subject: Re: JDBC Drivers for Java
  In-Reply-To: <200304141356.11542.franco@akyasociados.com.ar>
  References: <000801c30084$c5dd65d0$ef00a8c0@cfl.rr.com> <200304141356.11542.franco@akyasociados.com.ar>

* 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