Connecting an Java applet to a Postgre SQL database

J

Jesse

Hi all,

Can some ona help me with some examples of how to connect a PostgreSQL
databas via an java Applet anything would be more then welcome.

Thanks in forward,

Jesse
 
K

kevin

Hi all,

Can some ona help me with some examples of how to connect a PostgreSQL
databas via an java Applet anything would be more then welcome.

Thanks in forward,

Jesse

AFAIU...
i haven't tried connecting to an external resource from an applet. You
might find all kinds of nasties in java permissions and html source
tainting.

assuming none of those apply, you could do this...

1) define a Driver class. get the jdbc driver from the postgres site
and install it in your classpath

2) set a driver class for the postgres jdbc driver
try{
Class.forName("org.postgresql.Driver");
}
catch (ClassNotFoundException cnfe){
// crash and burn
}
3) make a connection to that driver passing your db credentials in
try {
Connection =
DriverManager.getConnection("jdbc:postgresql:<dbname>", <uid>,
<passwd>);
catch (SQLException sqle) {
// crash and burn
}

you should be able to access the db given all of the nasties haven't
got you.

HTH

kev.
 
R

Roedy Green

Can some ona help me with some examples of how to connect a PostgreSQL
databas via an java Applet anything would be more then welcome.


Normally you would talk to a servlet which in turn would do the
database access. You don't normally expose your database API to Applet
hackers.
 
O

Oscar kind

Jesse said:
Can some ona help me with some examples of how to connect a PostgreSQL
databas via an java Applet anything would be more then welcome.

Class.forName("org.postgresql.Driver");
String dbURL = "jdbc:postgresql:Test";
//String dbURL = "jdbc:postgresql://localhost/Test";
//String dbURL = "jdbc:postgresql://localhost:5432/Test";
Connection connection = DriverManager.getConnect(
dbURL, "username", "password");


Classpath, exception handling, etc. I'll leave as an exerise for you.


Oscar
 
R

Ryan Stewart

Oscar kind said:
Class.forName("org.postgresql.Driver");
String dbURL = "jdbc:postgresql:Test";
//String dbURL = "jdbc:postgresql://localhost/Test";
//String dbURL = "jdbc:postgresql://localhost:5432/Test";
Connection connection = DriverManager.getConnect(
dbURL, "username", "password");
That's DriverManager.getConnection(.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top