From: Marc <mhorv@comcast.net>
To: pgsql-jdbc@postgresql.org
To: pgsql-novice@postgresql.org
Subject: Applet Connectivity - PLEASE help
Date: Tue, 23 Jan 2007 00:26:00 -0500
Message-ID: <45B59C68.8080203@comcast.net> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: mhorv@comcast.net, pgsql-novice@postgresql.org
Subject: Re: Applet Connectivity - PLEASE help
In-Reply-To: <45B59C68.8080203@comcast.net>
References: <45B59C68.8080203@comcast.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox