Re: Applet Connectivity - PLEASE help - Mailing list pgsql-jdbc

From Frank Spies
Subject Re: Applet Connectivity - PLEASE help
Date
Msg-id 1169639475.7902.6.camel@ubuntu.localdomain.intern
Whole thread Raw
In response to Applet Connectivity - PLEASE help  (Marc <mhorv@comcast.net>)
List pgsql-jdbc
Have a look at this tutorial:

http://java.sun.com/developer/technicalArticles/Security/Signed/


Am Dienstag, den 23.01.2007, 00:26 -0500 schrieb Marc:
> OK, I'll say right up front I'm a postgres novice at best.
> I've spent quite some time researching this tonight and trying out a few
> things to no avail.
> The basic question is can an applet connect to a postgres database and
> if so how (I need specific details)?
> Postgres, the database, the web server and signed applet are all on the
> same machine.
> I'm using Postgres 8.2 and Java 1.5 w/ the postgresql-8.2-504.jdbc3 jdbc
> driver.
> The software works when run through my IDE (Eclipse) but not as an
> applet in a browser.
> I've set listen_addresses = '*' in postgresql.conf and my pg_hba
> settings are:
> local      all      all                               md5
> host       all      all         127.0.0.1/32          trust.
>
> Here's the code I'm using to try to make the connection where
> strServer = :jdbc:postgresql://localhost/Arco
> strDriver = org.postgresql.Driver
> strUser = postgres
> strPswd = fred
>
>     public DBConnection(Trace trace, JApplet p_applet)
>         throws Exception
>     {
>         URL    dbIniURL;
>         URLConnection  urlConn;
>         BufferedReader in;
>         int            vals = 0;
>         String         nextVal;
>         String         strProp;
>         String         strVal;
>         String         strUser = "";
>         String         strPswd = "";
>         int            pos;
>         Properties     props = new Properties();
>
>         try
>         {
>             System.out.println("Instantiate DBConnection.");
>
>             dbIniURL = new URL(p_applet.getDocumentBase(), "db.ini");
>             urlConn = dbIniURL.openConnection();
>             in = new BufferedReader(new
> InputStreamReader(urlConn.getInputStream()));
>
>             while (vals < 4)
>             {
>                 nextVal = in.readLine();
>                 vals = vals + 1;
>
>                 System.out.println("db.ini: " + nextVal.trim());
>
>                 pos = nextVal.indexOf(":");
>
>                 if (pos>0)
>                 {
>                     strProp = nextVal.substring(0,pos);
>                     strVal = nextVal.substring(pos+1);
>
>                     if (strProp.compareToIgnoreCase("Server") == 0)
>                     {
>                         strServer = strVal;
>                     }
>                     else if (strProp.compareToIgnoreCase("Driver") == 0)
>                     {
>                         strDriver = strVal;
>                     }
>                     else if (strProp.compareToIgnoreCase("User") == 0)
>                     {
>                         strUser = strVal;
>                     }
>                     else if (strProp.compareToIgnoreCase("Password") == 0)
>                     {
>                         strPswd = strVal;
>                     }
>                 }
>             }
>
>             drv = (Driver)Class.forName(strDriver).newInstance();
>             DriverManager.registerDriver(drv);
>
>
>             props.setProperty("user",strUser.trim());
>             props.setProperty("password",strPswd.trim());
>
>             System.out.println("Attempting to connecting to postgres
> db...");
>             dbConn= DriverManager.getConnection(strServer, props);
>             System.out.println("Connected to postgres db.");
>         }
>         catch (IOException ioe)
>         {
>             System.out.println("Error trying to connect to postgres db:");
>             ioe.printStackTrace();
>             throw new Exception(ioe.getMessage());
>         }
>     }
>
> The error I get in the console is:
> Java Plug-in 1.6.0
> Using JRE version 1.6.0 Java HotSpot(TM) Client VM
> User home directory = C:\Documents and Settings\Marc
>
>
> ----------------------------------------------------
> c:   clear console window
> f:   finalize objects on finalization queue
> g:   garbage collect
> h:   display this help message
> l:   dump classloader list
> m:   print memory usage
> o:   trigger logging
> p:   reload proxy configuration
> q:   hide console
> r:   reload policy configuration
> s:   dump system and deployment properties
> t:   dump thread list
> v:   dump thread stack
> x:   clear classloader cache
> 0-5: set trace level to <n>
> ----------------------------------------------------
>
> Init applet.
> Call new DBConnection.
> Instantiate DBConnection.
> db.ini: Server:jdbc:postgresql://localhost/Arco
> db.ini: Driver:org.postgresql.Driver
> Attempting to connecting to postgres db...
> org.postgresql.util.PSQLException: Something unusual has occured to
> cause the driver to fail. Please report this exception.
>     at org.postgresql.Driver.connect(Driver.java:276)
>     at java.sql.DriverManager.getConnection(Unknown Source)
>     at java.sql.DriverManager.getConnection(Unknown Source)
>     at db.DBConnection.<init>(DBConnection.java:169)
>     at ui.BaseApplet.init(BaseApplet.java:138)
>     at sun.applet.AppletPanel.run(Unknown Source)
>     at java.lang.Thread.run(Unknown Source)
> Caused by: java.security.AccessControlException: access denied
> (java.net.SocketPermission 127.0.0.1:5432 connect,resolve)
>     at java.security.AccessControlContext.checkPermission(Unknown Source)
>     at java.security.AccessController.checkPermission(Unknown Source)
>     at java.lang.SecurityManager.checkPermission(Unknown Source)
>     at java.lang.SecurityManager.checkConnect(Unknown Source)
>     at java.net.Socket.connect(Unknown Source)
>     at java.net.Socket.connect(Unknown Source)
>     at java.net.Socket.<init>(Unknown Source)
>     at java.net.Socket.<init>(Unknown Source)
>     at org.postgresql.core.PGStream.<init>(PGStream.java:59)
>     at
> org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:77)
>     at
> org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
>     at
> org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
>     at
> org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
>     at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
>     at org.postgresql.Driver.makeConnection(Driver.java:382)
>     at org.postgresql.Driver.connect(Driver.java:260)
>     ... 6 more
>
> I think that covers it. I'm pretty wiped out being as I've been working
> on this for about 4 hrs now.
> Your help is really appreciated!
>
> Thanks,
> Marc
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo@postgresql.org so that your
>        message can get through to the mailing list cleanly


pgsql-jdbc by date:

Previous
From: "Hemi"
Date:
Subject: Re: Applet Connectivity - PLEASE help
Next
From: Frank Spies
Date:
Subject: Compiling on JDK 6