pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
JDBC Drivers for Java
2+ messages / 2 participants
[nested] [flat]

* JDBC Drivers for Java
@ 2003-04-11 23:47  Greg Lugering <glugering@cfl.rr.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Greg Lugering @ 2003-04-11 23:47 UTC (permalink / raw)
  To: pgsql-admin

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

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

* Re: JDBC Drivers for Java
@ 2003-04-14 16:56  Franco Bruno Borghesi <franco@akyasociados.com.ar>
  parent: Greg Lugering <glugering@cfl.rr.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Franco Bruno Borghesi @ 2003-04-14 16:56 UTC (permalink / raw)
  To: Greg Lugering <glugering@cfl.rr.com>; pgsql-admin

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

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


end of thread, other threads:[~2003-04-14 16:56 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-04-11 23:47 JDBC Drivers for Java Greg Lugering <glugering@cfl.rr.com>
2003-04-14 16:56 ` Franco Bruno Borghesi <franco@akyasociados.com.ar>

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