public inbox for [email protected]  
help / color / mirror / Atom feed
[Pljava-dev] cannot set the classpath to a specific jar to get an external connection
8+ messages / 0 participants
[nested] [flat]

* [Pljava-dev] cannot set the classpath to a specific jar to get an external connection
@ 2010-06-03 08:52  
  0 siblings, 1 reply; 8+ messages in thread

From:  @ 2010-06-03 08:52 UTC (permalink / raw)

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




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection
@ 2010-06-03 12:15  
  parent: 
  0 siblings, 1 reply; 8+ messages in thread

From:  @ 2010-06-03 12:15 UTC (permalink / raw)

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




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection
@ 2010-06-03 12:50  
  parent: 
  0 siblings, 1 reply; 8+ messages in thread

From:  @ 2010-06-03 12:50 UTC (permalink / raw)

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




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection
@ 2010-06-03 12:56  
  parent: 
  0 siblings, 1 reply; 8+ messages in thread

From:  @ 2010-06-03 12:56 UTC (permalink / raw)

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




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection
@ 2010-06-03 13:39  
  parent: 
  0 siblings, 1 reply; 8+ messages in thread

From:  @ 2010-06-03 13:39 UTC (permalink / raw)

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




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection
@ 2010-06-03 13:43  
  parent: 
  0 siblings, 1 reply; 8+ messages in thread

From:  @ 2010-06-03 13:43 UTC (permalink / raw)

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




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection
@ 2010-06-03 14:32  
  parent: 
  0 siblings, 1 reply; 8+ messages in thread

From:  @ 2010-06-03 14:32 UTC (permalink / raw)

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
>





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection
@ 2010-06-04 08:42  
  parent: 
  0 siblings, 0 replies; 8+ messages in thread

From:  @ 2010-06-04 08:42 UTC (permalink / raw)

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





^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2010-06-04 08:42 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-06-03 08:52 [Pljava-dev] cannot set the classpath to a specific jar to get an external connection 
2010-06-03 12:15 ` [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection 
2010-06-03 12:50   ` [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection 
2010-06-03 12:56     ` [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection 
2010-06-03 13:39       ` [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection 
2010-06-03 13:43         ` [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection 
2010-06-03 14:32           ` [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection 
2010-06-04 08:42             ` [Pljava-dev] cannot set the classpath to a specific jar to get anexternal connection 

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox