atris / JDBC_FDW

FDW that wraps JDBC for PostgreSQL.It can be used to connect and fetch data from any data source that supports JDBC
Other
67 stars 38 forks source link

ClassNotFoundException using two servers. #2

Closed brunosimioni closed 12 years ago

brunosimioni commented 12 years ago

It appears not working properly when using two distinct servers with jdbc_fdw. The second classpath is just ignored after quering the first one.

Steps to reproduce.

  1. Create server serverA FOREIGN DATA WRAPPER ... OPTIONS (driverA)
  2. Create server serverB FOREIGN DATA WRAPPER ... OPTIONS (driverB)
  3. CREATE FOREIGN TABLE TableA ON SERVER A.
  4. CREATE FOREIGN TABLE TableB ON SERVER B.
  5. SELECT on TableA works.
  6. SELECT on TableB throws java.lang.ClassNotFoundException:

The inverse order throws the same exception too. Executing the step 6 first, and then step 5, but the serverA driver is not found.

StackTrace:

ERROR: java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at JDBCUtils.Initialize(JDBCUtils.java:78)

atris commented 12 years ago

Strange.This is the exact bug we fixed using Dynamic Class loading during coding of the project itself.I will try to reproduce the bug,but it is unlikely that it will get reproduced(For the solution,please see JDBCDriverLoader.java and its use in JDBCUtils.java)

Are you sure you are on the latest version of the project?

Atri

On Wed, Sep 26, 2012 at 7:01 PM, brunosimioni notifications@github.comwrote:

It appears not working properly when using two distinct servers with jdbc_fdw. The second classpath is just ignored after quering the first one.

Steps to reproduce.

  1. Create server serverA FOREIGN DATA WRAPPER ... OPTIONS (driverA)
  2. Create server serverB FOREIGN DATA WRAPPER ... OPTIONS (driverB)
  3. CREATE FOREIGN TABLE TableA ON SERVER A.
  4. CREATE FOREIGN TABLE TableB ON SERVER B.
  5. SELECT on TableA works.
  6. SELECT on TableB throws java.lang.ClassNotFoundException:

The inverse order throws the same exception too. Executing the step 6 first, and then step 5, but the serverA driver is not found.

StackTrace:

ERROR: java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at JDBCUtils.Initialize(JDBCUtils.java:78)

— Reply to this email directly or view it on GitHubhttps://github.com/atris/JDBC_FDW/issues/2.

Regards,

Atri l'apprenant

atris commented 12 years ago

Could you give me more details(The databases A and B,and the name of the drivers you are using for them?)

Atri

On Wed, Sep 26, 2012 at 10:08 PM, Atri Sharma atri.jiit@gmail.com wrote:

Strange.This is the exact bug we fixed using Dynamic Class loading during coding of the project itself.I will try to reproduce the bug,but it is unlikely that it will get reproduced(For the solution,please see JDBCDriverLoader.java and its use in JDBCUtils.java)

Are you sure you are on the latest version of the project?

Atri

On Wed, Sep 26, 2012 at 7:01 PM, brunosimioni notifications@github.comwrote:

It appears not working properly when using two distinct servers with jdbc_fdw. The second classpath is just ignored after quering the first one.

Steps to reproduce.

  1. Create server serverA FOREIGN DATA WRAPPER ... OPTIONS (driverA)
  2. Create server serverB FOREIGN DATA WRAPPER ... OPTIONS (driverB)
  3. CREATE FOREIGN TABLE TableA ON SERVER A.
  4. CREATE FOREIGN TABLE TableB ON SERVER B.
  5. SELECT on TableA works.
  6. SELECT on TableB throws java.lang.ClassNotFoundException:

The inverse order throws the same exception too. Executing the step 6 first, and then step 5, but the serverA driver is not found.

StackTrace:

ERROR: java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at JDBCUtils.Initialize(JDBCUtils.java:78)

— Reply to this email directly or view it on GitHubhttps://github.com/atris/JDBC_FDW/issues/2.

Regards,

Atri l'apprenant

Regards,

Atri l'apprenant

brunosimioni commented 12 years ago

For sure!

Yes, I'm using the latest version of repo (cloned yesterday).

More details:

  1. Git clone, and make && make install from contrib source.
  2. /bin/psql db -U usera; (all commands executed inside psql).
  3. CREATE EXTENSION jdbc_fdw;
  4. CREATE SERVER serverA FOREIGN DATA WRAPPER jdbc_fdw OPTIONS(drivername 'org.postgresql.Driver',url 'jdbc:postgresql://localhost/db1',jarfile '(...)/jdbcDrivers/postgresql-9.1-901.jdbc4.jar',maxheapsize '600');
  5. CREATE USER MAPPING FOR userA SERVER serverA options (username 'usera', password '');
  6. CREATE FOREIGN TABLE tableA (...) SERVER serverA OPTIONS (table 'ftablea');
  7. SELECT * FROM tableA (works fine).
  8. CREATE SERVER serverB FOREIGN DATA WRAPPER jdbc_fdw OPTIONS(drivername 'net.sourceforge.jtds.jdbc.Driver',url 'jdbc:jtds:sqlserver://serverip/db2',jarfile '(...)/jdbcDrivers/jtds-1.2.4.jar',maxheapsize '600');
  9. CREATE USER MAPPING FOR userB SERVER serverB options (username 'userb' password '');
  10. CREATE FOREIGN TABLE tableB (...) SERVER serverB OPTIONS (table 'ftableb');
  11. SELECT * FROM tableB;

ERROR: java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at JDBCUtils.Initialize(JDBCUtils.java:78)

Exiting psql and entering again, and executing the inverse order, brings me the same expection but the other driver.

brunosimioni commented 12 years ago

Connecting to the database via JDBC (hibernate), instead of psql works fine. The problem appears when I acess the foreign table via psql.

atris commented 12 years ago

In both cases,whenever you are able to fetch data from PostgreSQL/SQL Server,it is fetching data and working correctly,right?I think it is an issue with the dynamic loading of the JDBC Driver.

Atri

On Wed, Sep 26, 2012 at 1:36 PM, brunosimioni notifications@github.comwrote:

Connecting to the database via JDBC (hibernate), instead of psql works fine. The problem appears when I acess the foreign table via psql.

— Reply to this email directly or view it on GitHubhttps://github.com/atris/JDBC_FDW/issues/2#issuecomment-8898251.

Regards,

Atri l'apprenant

atris commented 12 years ago

Closed thanks to patch by Bruno