Connecting an Java applet to a Postgre SQL database

Discussion in 'Java' started by Jesse, Jun 5, 2004.

  1. Jesse

    Jesse Guest

    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
     
    Jesse, Jun 5, 2004
    #1
    1. Advertising

  2. Jesse

    kevin Guest

    (Jesse) wrote in message news:<>...
    > 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.
     
    kevin, Jun 5, 2004
    #2
    1. Advertising

  3. Jesse

    Roedy Green Guest

    On 5 Jun 2004 01:29:49 -0700, (Jesse)
    wrote or quoted :

    >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.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jun 5, 2004
    #3
  4. Jesse

    Oscar kind Guest

    Jesse <> wrote:
    > 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

    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
     
    Oscar kind, Jun 6, 2004
    #4
  5. Jesse

    Ryan Stewart Guest

    "Oscar kind" <> wrote in message
    news:...
    > Jesse <> wrote:
    > > 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");
    >

    That's DriverManager.getConnection(.....
     
    Ryan Stewart, Jun 6, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    357
    Lee Harr
    May 4, 2004
  2. =?ISO-8859-1?Q?Eino_M=E4kitalo?=
    Replies:
    1
    Views:
    458
    Max M
    Dec 9, 2004
  3. projecktzero
    Replies:
    4
    Views:
    614
    projecktzero
    Jun 28, 2005
  4. =?Utf-8?B?TmVpbCBQYWRkb2Nr?=

    Connecting to SQL 2000 database with SQL 2005 tools installed

    =?Utf-8?B?TmVpbCBQYWRkb2Nr?=, May 2, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    420
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    May 2, 2007
  5. Jagan Jacob

    Access Postgre Sql

    Jagan Jacob, Nov 29, 2010, in forum: Ruby
    Replies:
    1
    Views:
    92
    Daniel Hernández
    Nov 29, 2010
Loading...

Share This Page