AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Postgres and JDBC?!

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
tem2
Guest





PostPosted: Thu Jan 27, 2005 3:58 pm    Post subject: Postgres and JDBC?! Reply with 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
Daniel Dittmar
Guest





PostPosted: Thu Jan 27, 2005 4:09 pm    Post subject: Re: Postgres and JDBC?! Reply with quote



tem2 wrote:
Quote:
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!

http://www.fankhausers.com/postgresql/jdbc/
through http://www.google.com/search?q=postgresql+jdbc+example

Daniel

Back to top
Thomas Kellerer
Guest





PostPosted: Thu Jan 27, 2005 4:24 pm    Post subject: Re: Postgres and JDBC?! Reply with quote



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





PostPosted: Thu Jan 27, 2005 8:31 pm    Post subject: Re: Postgres and JDBC?! Reply with quote

"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





PostPosted: Thu Jan 27, 2005 10:21 pm    Post subject: Re: Postgres and JDBC?! Reply with quote

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





PostPosted: Thu Jan 27, 2005 10:32 pm    Post subject: Re: Postgres and JDBC?! Reply with quote

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





PostPosted: Fri Jan 28, 2005 4:42 am    Post subject: Re: Postgres and JDBC?! Reply with quote

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





PostPosted: Fri Jan 28, 2005 7:56 am    Post subject: Re: Postgres and JDBC?! Reply with 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();
}
}

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





PostPosted: Sun Jan 30, 2005 6:07 pm    Post subject: Re: Postgres and JDBC?! Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.