Jdbc Connection Problem

One Star

Jdbc Connection Problem

Hi.
I'm getting this error :
Exception in component tJDBCInput_1
java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method)
The jdbc component causes the error with Oracle database but not with DB2.
The property "Driver JAR > Jar name" it set dinamically using a context variable.
If I add a new "do nothing" general jdbc component (for example a connection) connecting to a different Oracle database the drivers are loaded and the job works fine.
The only thing I notice is that when I created the Database Connection I've also created the context using the  "Export as context" button specifying a db2 jdbc driver. When I try to use this connection I change the cotext value dinamically using the Oracle parameters.
Thank a lot.
Andrea
Moderator

Re: Jdbc Connection Problem

Hi,
Could you please take a look at a related forum:http://community.talend.com:80/t5/Deployment/resolved-java-lang-ClassNotFoundException-oracle-jdbc-d... to see if it is OK with you?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Five Stars

Re: Jdbc Connection Problem

You can't load JDBC drivers during runtime.
Please refer to: http://www.kfu.com/~nsayer/Java/dyn-jdbc.html
One Star

Re: Jdbc Connection Problem

Hi,
actually you can, but you will have to use a workaround: when you create a General JDBC connection, even using the Export as Context button, you have to specify the JDBC Driver JAR (let's assume you chose a DB2 JDBC Driver). Then, in the corresponding Context Group, you can change the driver to use it with other DB Types (for example, selecting an Oracle JDBC Driver), BUT if you use it in your job the componente won't load correctly the new driver when you run the job, causing the error you posted. 
But if you add a General JDBC component to your Job with a JDBC connection orignally created with an Oracle JDBC Driver and configured with a JDBC Oracle Driver in its Context Group, then your job will run correctly! Please note that the second General JDBC "Oracle" Component (let's call it the DUMMY_CONNECTION) hasn't to be configured with a "real" connection. You can leave all of his contexts blank (or default) except for jdbc driver and class. To avoid errors, you can put a DO_NOTHING tJava component linked with an impossible "if" condition (see picture)


I know it's a workaround, but I haven't figured out any other solution, it seems to be a Talend bug.
You can even create a DUMMY Connection job, where you can put as many Dummy DB components as the DB types you want your project to work with, and then add this job with the tRunJob component to all of your project jobs (see pictures below). I hasn't to be linked to anything.



Hope this solution can work for you!
Moderator

Re: Jdbc Connection Problem

Hi Andrea,

Is there any update for your issue?

Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Jdbc Connection Problem

Hi Andrea,

Is there any update for your issue?

Best regards
Sabrina

Hi Sabrina.
I tried andrea.sarti workaround and it seems good , it works fine !
Many thanks.
Andrea