From: | Franco Bruno Borghesi <franco(at)akyasociados(dot)com(dot)ar> |
---|---|
To: | "Greg Lugering" <glugering(at)cfl(dot)rr(dot)com>, <pgsql-admin(at)postgresql(dot)org> |
Subject: | Re: JDBC Drivers for Java |
Date: | 2003-04-14 16:56:11 |
Message-ID: | 200304141356.11542.franco@akyasociados.com.ar |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)cfl(dot)rr(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Oleg Bartunov | 2003-04-14 18:56:09 | Re: Need two languages in the database: Russian and English |
Previous Message | Michiel Lange | 2003-04-14 16:45:17 | Re: Killing only one postmaster |