Lists: | pljava-dev |
---|
From: | fluca1978 at infinito(dot)it (Luca Ferrari) |
---|---|
To: | |
Subject: | [Pljava-dev] cannot set the classpath to a specific jar to get an external connection |
Date: | 2010-06-03 08:52:32 |
Message-ID: | 201006031052.33192.fluca1978@infinito.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
Hi all,
not sure if what I'd like to do is possible, but I'd like to use JDBC within a
pl/java function to extract data from another database (something similar to
dbilink). However if I try to change the connection to another URL rather that
"jdbc:default:connection" I got an error saying there is no suitable driver,
so I tried to add explicitly the postgresql jar to the schema, but the
following fails:
select sqlj.set_classpath('public',
'/java/jars/postgresql-8.4-701.jdbc4.jar');
ERROR: java.sql.SQLException: No such jar:
/java/jars/postgresql-8.4-701.jdbc4.jar
So my questions are:
1) what am I missing in setting the classpath?
2) is it possible to open a connection to another database cluster?
Thanks,
Luca
From: | Jon(dot)Roberts at asurion(dot)com (Roberts, Jon) |
---|---|
To: | |
Subject: | [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection |
Date: | 2010-06-03 12:15:30 |
Message-ID: | 8661B041D452404E8088FBD47D2443BE019EC4FE@NDCEXCUS703.int.asurion.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
I think you need to first install the jar and then set the class path.
For example:
select * from
sqlj.install_jar('file:///java/jars/postgresql-8.4-701.jdbc4.jar',
'example_jar', true);
select sqlj.set_classpath('public', 'example_jar');
I use PL/Java to connect to other databases (Oracle, SQL Server, and
PostgreSQL) but I created a single Jar with all of my drivers and load
that to the database.
Jon
-----Original Message-----
From: pljava-dev-bounces at pgfoundry.org
[mailto:pljava-dev-bounces at pgfoundry.org] On Behalf Of Luca Ferrari
Sent: Thursday, June 03, 2010 3:53 AM
To: pljava-dev at pgfoundry.org
Subject: [Pljava-dev] cannot set the classpath to a specific jar to get
anexternal connection
Hi all,
not sure if what I'd like to do is possible, but I'd like to use JDBC
within a
pl/java function to extract data from another database (something
similar to
dbilink). However if I try to change the connection to another URL
rather that
"jdbc:default:connection" I got an error saying there is no suitable
driver,
so I tried to add explicitly the postgresql jar to the schema, but the
following fails:
select sqlj.set_classpath('public',
'/java/jars/postgresql-8.4-701.jdbc4.jar');
ERROR: java.sql.SQLException: No such jar:
/java/jars/postgresql-8.4-701.jdbc4.jar
So my questions are:
1) what am I missing in setting the classpath?
2) is it possible to open a connection to another database cluster?
Thanks,
Luca
_______________________________________________
Pljava-dev mailing list
Pljava-dev at pgfoundry.org
http://pgfoundry.org/mailman/listinfo/pljava-dev
From: | fluca1978 at infinito(dot)it (Luca Ferrari) |
---|---|
To: | |
Subject: | [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection |
Date: | 2010-06-03 12:50:09 |
Message-ID: | 201006031450.10453.fluca1978@infinito.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
On Thursday 03 June 2010 02:15:30 pm Roberts, Jon's cat walking on the
keyboard wrote:
> I think you need to first install the jar and then set the class path.
>
> For example:
> select * from
> sqlj.install_jar('file:///java/jars/postgresql-8.4-701.jdbc4.jar',
> 'example_jar', true);
> select sqlj.set_classpath('public', 'example_jar');
>
Yes, I've installed the jar before ( I did not mention) and then I was able to
set the classpath using the jar alias. However, keeping the jar separated or
merging them into a single jar does not solve the problem and the error still
is:
ERROR: java.sql.SQLException: No suitable driver found for
jdbc:postgresql://localhost/myDb
and in the logs I've got the stacktrace:
java.sql.SQLException: No suitable driver found for
jdbc:postgresql://localhost/myDB
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at itpug.pljava.RowGenerator.getResultSet(RowGenerator.java:40)
at
org.postgresql.pljava.internal.ResultSetPicker.<init>(ResultSetPicker.java:25)
Summarizing this is what I've done:
1) sqlj.replace_jar to my new jar containing the Java client
2) sqlj.install_jar for the postgresql driver jar
3) set the classpath so that now I've got:
select sqlj.get_classpath('public');
get_classpath
---------------
driver:myJar
(1 row)
with driver the jar for the jdbc driver, and myjar the jar of my client.
Any suggestion?
Luca
From: | Jon(dot)Roberts at asurion(dot)com (Roberts, Jon) |
---|---|
To: | |
Subject: | [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection |
Date: | 2010-06-03 12:56:54 |
Message-ID: | 8661B041D452404E8088FBD47D2443BE019EC515@NDCEXCUS703.int.asurion.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
How are you connecting? Is it something like this:
Class.forName("org.postgresql.Driver");
String connectionUrl = "jdbc:postgresql://" + server +
":" + port + "/" + database;
conn = DriverManager.getConnection(connectionUrl,
userName, password);
Jon
-----Original Message-----
From: Luca Ferrari [mailto:fluca1978 at infinito.it]
Sent: Thursday, June 03, 2010 7:50 AM
To: Roberts, Jon
Cc: pljava-dev at pgfoundry.org
Subject: Re: [Pljava-dev] cannot set the classpath to a specific jar to
get anexternal connection
On Thursday 03 June 2010 02:15:30 pm Roberts, Jon's cat walking on the
keyboard wrote:
> I think you need to first install the jar and then set the class path.
>
> For example:
> select * from
> sqlj.install_jar('file:///java/jars/postgresql-8.4-701.jdbc4.jar',
> 'example_jar', true);
> select sqlj.set_classpath('public', 'example_jar');
>
Yes, I've installed the jar before ( I did not mention) and then I was
able to
set the classpath using the jar alias. However, keeping the jar
separated or
merging them into a single jar does not solve the problem and the error
still
is:
ERROR: java.sql.SQLException: No suitable driver found for
jdbc:postgresql://localhost/myDb
and in the logs I've got the stacktrace:
java.sql.SQLException: No suitable driver found for
jdbc:postgresql://localhost/myDB
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at itpug.pljava.RowGenerator.getResultSet(RowGenerator.java:40)
at
org.postgresql.pljava.internal.ResultSetPicker.<init>(ResultSetPicker.ja
va:25)
Summarizing this is what I've done:
1) sqlj.replace_jar to my new jar containing the Java client
2) sqlj.install_jar for the postgresql driver jar
3) set the classpath so that now I've got:
select sqlj.get_classpath('public');
get_classpath
---------------
driver:myJar
(1 row)
with driver the jar for the jdbc driver, and myjar the jar of my client.
Any suggestion?
Luca
From: | fluca1978 at infinito(dot)it (Luca Ferrari) |
---|---|
To: | |
Subject: | [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection |
Date: | 2010-06-03 13:39:14 |
Message-ID: | 201006031539.14616.fluca1978@infinito.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
On Thursday 03 June 2010 02:56:54 pm Roberts, Jon's cat walking on the
keyboard wrote:
> How are you connecting? Is it something like this:
>
> Class.forName("org.postgresql.Driver");
>
> String connectionUrl = "jdbc:postgresql://" + server +
> ":" + port + "/" + database;
>
> conn = DriverManager.getConnection(connectionUrl,
> userName, password);
Using either reflection or direct instantation I've got a new exception:
java.lang.NoClassDefFoundError: Could not initialize class
sun.security.provider.NativePRNG
at sun.security.provider.Sun.<init>(Sun.java:91)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at sun.security.jca.ProviderConfig$3.run(ProviderConfig.java:240)
at java.security.AccessController.doPrivileged(Native Method)
at
sun.security.jca.ProviderConfig.doLoadProvider(ProviderConfig.java:225)
at sun.security.jca.ProviderConfig.getProvider(ProviderConfig.java:205)
at sun.security.jca.ProviderList.getProvider(ProviderList.java:215)
at sun.security.jca.ProviderList.getService(ProviderList.java:313)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:140)
at java.security.Security.getImpl(Security.java:659)
at java.security.MessageDigest.getInstance(MessageDigest.java:129)
at org.postgresql.util.MD5Digest.encode(MD5Digest.java:46)
at
org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:339)
at
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:108)
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.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
at
org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:30)
at
org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393)
at org.postgresql.Driver.connect(Driver.java:267)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at itpug.pljava.RowGenerator.getResultSet(RowGenerator.java:43)
at
org.postgresql.pljava.internal.ResultSetPicker.<init>(ResultSetPicker.java:25)
The code I use is the following:
public ResultSet getResultSet() throws SQLException {
org.postgresql.Driver driver = new org.postgresql.Driver();
Connection connection = DriverManager.getConnection( this.databaseName,
this.username, this.password );
Statement statement = connection.createStatement();
return statement.executeQuery(" SELECT * FROM "+ this.tableName );
}
Any idea?
Thanks,
Luca
From: | fluca1978 at infinito(dot)it (Luca Ferrari) |
---|---|
To: | |
Subject: | [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection |
Date: | 2010-06-03 13:43:21 |
Message-ID: | 201006031543.21939.fluca1978@infinito.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
On Thursday 03 June 2010 03:39:14 pm Luca Ferrari's cat walking on the
keyboard wrote:
> java.lang.NoClassDefFoundError: Could not initialize class
> sun.security.provider.NativePRNG
I've noted that when the function is called the first time the logs are
differents and provide the following stacktrace:
Caused by: java.lang.SecurityException: read on /dev/random
at
org.postgresql.pljava.internal.Backend$1.assertPermission(Backend.java:176)
at
org.postgresql.pljava.internal.Backend$PLJavaSecurityManager.nonRecursiveCheck(Backend.java:111)
at
org.postgresql.pljava.internal.Backend$PLJavaSecurityManager.checkPermission(Backend.java:89)
at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
at java.io.File.exists(File.java:731)
at sun.security.provider.NativePRNG$1.run(NativePRNG.java:60)
at java.security.AccessController.doPrivileged(Native Method)
at sun.security.provider.NativePRNG.initIO(NativePRNG.java:57)
at sun.security.provider.NativePRNG.<clinit>(NativePRNG.java:54)
... 31 more
2010-06-03 15:39:43 CEST ERROR: java.lang.ExceptionInInitializerError
so it seems a problem of reading /dev/random, even if the user has the
permissions:
$ ls -l /dev/random
crw-rw-rw- 1 root root 1, 8 2010-06-03 15:31 /dev/random
Any idea?
Thanks,
Luca
From: | thomas at tada(dot)se (Thomas Hallgren) |
---|---|
To: | |
Subject: | [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection |
Date: | 2010-06-03 14:32:41 |
Message-ID: | 4C07BD09.1070302@tada.se |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
PL/Java is implemented as a trusted procedure language. It will
therefore prevent all access to the filesystem. You can use language
"javaU" if you want untrusted. More details here:
http://wiki.tada.se/index.php/Security.
Regards,
Thomas Hallgren
On 2010-06-03 15:43, Luca Ferrari wrote:
> On Thursday 03 June 2010 03:39:14 pm Luca Ferrari's cat walking on the
> keyboard wrote:
>
>> java.lang.NoClassDefFoundError: Could not initialize class
>> sun.security.provider.NativePRNG
>>
>
> I've noted that when the function is called the first time the logs are
> differents and provide the following stacktrace:
>
> Caused by: java.lang.SecurityException: read on /dev/random
> at
> org.postgresql.pljava.internal.Backend$1.assertPermission(Backend.java:176)
> at
> org.postgresql.pljava.internal.Backend$PLJavaSecurityManager.nonRecursiveCheck(Backend.java:111)
> at
> org.postgresql.pljava.internal.Backend$PLJavaSecurityManager.checkPermission(Backend.java:89)
> at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
> at java.io.File.exists(File.java:731)
> at sun.security.provider.NativePRNG$1.run(NativePRNG.java:60)
> at java.security.AccessController.doPrivileged(Native Method)
> at sun.security.provider.NativePRNG.initIO(NativePRNG.java:57)
> at sun.security.provider.NativePRNG.<clinit>(NativePRNG.java:54)
> ... 31 more
> 2010-06-03 15:39:43 CEST ERROR: java.lang.ExceptionInInitializerError
>
>
> so it seems a problem of reading /dev/random, even if the user has the
> permissions:
>
> $ ls -l /dev/random
> crw-rw-rw- 1 root root 1, 8 2010-06-03 15:31 /dev/random
>
>
> Any idea?
>
> Thanks,
> Luca
> _______________________________________________
> Pljava-dev mailing list
> Pljava-dev at pgfoundry.org
> http://pgfoundry.org/mailman/listinfo/pljava-dev
>
From: | fluca1978 at infinito(dot)it (Luca Ferrari) |
---|---|
To: | |
Subject: | [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection |
Date: | 2010-06-04 08:42:18 |
Message-ID: | 201006041042.18443.fluca1978@infinito.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
On Thursday 03 June 2010 04:32:41 pm Thomas Hallgren's cat walking on the
keyboard wrote:
> PL/Java is implemented as a trusted procedure language. It will
> therefore prevent all access to the filesystem. You can use language
> "javaU" if you want untrusted. More details here:
> http://wiki.tada.se/index.php/Security.
Thanks, it solved the problem!
Luca