| View previous topic :: View next topic |
| Author |
Message |
tem2 Guest
|
Posted: Thu Jan 27, 2005 3:58 pm Post subject: Postgres and JDBC?! |
|
|
Hi
Can anyone tell me how to establish a connection to the University Postgres
database using JDBC. I've looked at loads of books and Web sites on the
topic but I can't really get my head around it!
This is what I've got but it's not working:
import java.sql.*;
public class Connect
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:PostgreSQL";
Connection con = DriverManager.getConnection(penguin.kent.ac.uk,
"myusername", "mypassword");
}
Any help would be really helpful.
Thanks in advance.
|
|
| Back to top |
|
 |
Daniel Dittmar Guest
|
|
| Back to top |
|
 |
Thomas Kellerer Guest
|
Posted: Thu Jan 27, 2005 4:24 pm Post subject: Re: Postgres and JDBC?! |
|
|
On 27.01.2005 16:58 tem2 wrote:
| Quote: |
import java.sql.*;
public class Connect
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:PostgreSQL";
Connection con = DriverManager.getConnection(penguin.kent.ac.uk,
"myusername", "mypassword");
}
|
At first glance I would say:
Connection con = DriverManager.getConnection(url,"myusername", "mypassword");
getConnection() needs a JDBC URL, not a server name.
Thomas
|
|
| Back to top |
|
 |
Wiseguy Guest
|
Posted: Thu Jan 27, 2005 8:31 pm Post subject: Re: Postgres and JDBC?! |
|
|
"tem2" <tem2 (AT) kent (DOT) ac.uk> scribbled on the stall wall:
| Quote: | Hi
Can anyone tell me how to establish a connection to the University Postgres
database using JDBC. I've looked at loads of books and Web sites on the
topic but I can't really get my head around it!
|
University Postgres? I don't think it has been called that since the
early 90s. To avoid confusion you might just want to call it Postgres.
I'm not aware of ANYONE who uses the old university code and it most
surely would not support JDBC.
|
|
| Back to top |
|
 |
Luke Webber Guest
|
Posted: Thu Jan 27, 2005 10:21 pm Post subject: Re: Postgres and JDBC?! |
|
|
Wiseguy wrote:
| Quote: | "tem2" <tem2 (AT) kent (DOT) ac.uk> scribbled on the stall wall:
Hi
Can anyone tell me how to establish a connection to the University Postgres
database using JDBC. I've looked at loads of books and Web sites on the
topic but I can't really get my head around it!
University Postgres? I don't think it has been called that since the
early 90s. To avoid confusion you might just want to call it Postgres.
I'm not aware of ANYONE who uses the old university code and it most
surely would not support JDBC.
|
Um, I think you'll find he's referring to the PostgreSQL server located
at the University of Kent.
Luke
|
|
| Back to top |
|
 |
Wiseguy Guest
|
Posted: Thu Jan 27, 2005 10:32 pm Post subject: Re: Postgres and JDBC?! |
|
|
Luke Webber <luke (AT) webber (DOT) com.au> scribbled on the stall wall:
| Quote: | Wiseguy wrote:
"tem2" <tem2 (AT) kent (DOT) ac.uk> scribbled on the stall wall:
Hi
Can anyone tell me how to establish a connection to the University Postgres
database using JDBC. I've looked at loads of books and Web sites on the
topic but I can't really get my head around it!
University Postgres? I don't think it has been called that since the
early 90s. To avoid confusion you might just want to call it Postgres.
I'm not aware of ANYONE who uses the old university code and it most
surely would not support JDBC.
Um, I think you'll find he's referring to the PostgreSQL server located
at the University of Kent.
|
WELL! That does make a bit more sense.
It certainly makes more sense than trying to use "University Postgres" or
Posgres95 with JDBC.
|
|
| Back to top |
|
 |
EricF Guest
|
Posted: Fri Jan 28, 2005 4:42 am Post subject: Re: Postgres and JDBC?! |
|
|
In article <ctb333$qd$1 (AT) oheron (DOT) kent.ac.uk>, "tem2" <tem2 (AT) kent (DOT) ac.uk> wrote:
| Quote: | Hi
Can anyone tell me how to establish a connection to the University Postgres
database using JDBC. I've looked at loads of books and Web sites on the
topic but I can't really get my head around it!
This is what I've got but it's not working:
import java.sql.*;
public class Connect
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:PostgreSQL";
Connection con = DriverManager.getConnection(penguin.kent.ac.uk,
"myusername", "mypassword");
}
Any help would be really helpful.
Thanks in advance.
|
I'd start with Google but I don't have a clue why you are trying to use the
jdbc odbc bridge. You need a postgress driver ...
Class.forName("org.postgresql.Driver");
As well as the correct classpath to it.
You define a url and you don't use it. What you have for the url should be the
driver you try to load. Your url should look something like ...
jdbc:postgresql://host:port/database
host is probably the penguin.kent...string, Postgres usually has a default
port of 5432. Now what the database should be - better ask the professor.
Eric
|
|
| Back to top |
|
 |
Dr.Adolf Daniel Guest
|
Posted: Fri Jan 28, 2005 7:56 am Post subject: Re: Postgres and JDBC?! |
|
|
It's quite easy and it works always. - In the following example pluto is
the host and wachter is the database name.
public void getConnection() {
try {
String userId = "postgres";
String password = "postgres";
String driver = "org.postgresql.Driver";
String url = "jdbc:postgresql://pluto/wachter";
Class.forName(driver).newInstance();
connection = DriverManager.getConnection(url, userId,
password);
Statement s = connection.createStatement();
s.close();
System.out.println("getConnection() was successfull!");
} catch (Exception e) {
e.printStackTrace();
}
}
Regards
Doelf
tem2 wrote:
| Quote: | Hi
Can anyone tell me how to establish a connection to the University Postgres
database using JDBC. I've looked at loads of books and Web sites on the
topic but I can't really get my head around it!
This is what I've got but it's not working:
import java.sql.*;
public class Connect
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:PostgreSQL";
Connection con = DriverManager.getConnection(penguin.kent.ac.uk,
"myusername", "mypassword");
}
Any help would be really helpful.
Thanks in advance.
|
|
|
| Back to top |
|
 |
Jon Martin Solaas Guest
|
Posted: Sun Jan 30, 2005 6:07 pm Post subject: Re: Postgres and JDBC?! |
|
|
Dr.Adolf Daniel wrote:
| Quote: | It's quite easy and it works always. - In the following example pluto is
the host and wachter is the database name.
public void getConnection() {
try {
String userId = "postgres";
String password = "postgres";
String driver = "org.postgresql.Driver";
String url = "jdbc:postgresql://pluto/wachter";
Class.forName(driver).newInstance();
connection = DriverManager.getConnection(url, userId,
password);
Statement s = connection.createStatement();
s.close();
System.out.println("getConnection() was successfull!");
} catch (Exception e) {
e.printStackTrace();
}
}
|
Also I think you have to make sure postmaster is started with the -i
option and that tcp-ip connections are allowed in pg_hba.conf, otherwise
the jdbc-driver won't be able to connect. It's all documented.
--
jonmartin.solaas¤h0tm4i1
|
|
| Back to top |
|
 |
|