The Eclipse framework uses a different class loader so that  
Class.forName() won't work. The easiest solution for you (if your  
database driver is fixed) is to add the .jar file to the plugin  
itself.  The jar file needs to be on the build path and the  
MANIFEST.MF of your plugin should have a line such as

Bundle-ClassPath: driver.jar,
   bin/
   .

This can be done via the Runtime tab of the plugin in the Eclipse  
plugin development environment. Also check the Build tab to make sure  
the jar is being included in the binary build.

The other alternative is to use the org.topbraid.core.util.DBUtil  
class (use auto-complete to see the available static members. This has  
a getDriver class which should include support for MySQL.

Holger


On Aug 5, 2009, at 12:11 PM, CF: wrote:

>
> As in my previous post I am creating a custom SPARLQ java function
> that will work with mysql tables.
>
> I have set up my test mySQL database and written a simple function
> (source code at the bottom of the post) that tries to estiblish a
> connection to the database from topbraid.
>
> I have a stacktrace in my program and it sends back the following
> error
>
>   java.lang.ClassNotFoundExceptions: com.mysql.jdbc.Driverat ........
>
> I have traced the error back to this line in my code
>
>     Class.forName("com.mysql.jdbc.Driver").newinstance();
>
> From what I understand The exception is being through becasue it is
> not loading the
> MySQL Connector/J correctly.
>
> I have placed the mysql-connector-java-5.1.8-bin.jar in the following
> directory
>
>    C:\Program Files\TopbraidComposerME\jre\lib\ext\
>
> Any Ideas/suggestions?
>
> Source code below
>
>
> package com.my.project.functions;
>
>
>
> import org.topbraid.sparql.functions.AbstractFunction1;
>
>
>
>
>
> import com.hp.hpl.jena.graph.Node;
>
> import com.hp.hpl.jena.sparql.expr.NodeValue;
>
> import com.hp.hpl.jena.sparql.function.FunctionEnv;
>
>
>
> import java.io.StringWriter;
>
> import java.io.PrintWriter;
>
> import java.sql.*;
>
>
>
>
>
>
>
> public class MaxFunction extends AbstractFunction1
>
> {
>
>
>
>       @Override
>
>       protected NodeValue exec(Node predicate, FunctionEnv env)
>
>       {
>
>               Connection conn = null;
>
>
>
>
>
>
>
>               String test = "lets start";
>
>
>
>               try
>
>               {
>
>                       String userName = "testuser";
>
>                       String passWord = "testpassword";
>
>                       String url = "jdbc:mysql://localhost/testdatabase";
>
>                       Class.forName("com.mysql.jdbc.Driver").newInstance();
>
>                       conn = DriverManager.getConnection(url, userName, 
> passWord);
>
>                       System.out.println("Database connection established");
>
>
>
>                       test = "Database connection established";
>
>
>
>               }
>
>               catch (Exception e)
>
>               {
>
>                       StringWriter sw = new StringWriter();
>
>                       e.printStackTrace(new PrintWriter(sw));
>
>                       String stacktrace = sw.toString();
>
>
>
>
>
>                       System.err.println("Cannot connect to database server");
>
>
>
>                       test = stacktrace;
>
>
>
>               }
>
>               finally
>
>               {
>
>                       if (conn != null)
>
>                       {
>
>                               try
>
>                               {
>
>                                       conn.close();
>
>                                       System.out.println("Database connection 
> Terminated");
>
>                               }
>
>                               catch (Exception e) {/* ignore close errors */}
>
>                       }
>
>               }
>
>
>
>
>
>
>
>               //NodeValue.makeString(test);
>
>
>
> //NodeValue.makeNode(predicate);
>
>               //NodeValue.makeInteger(5);
>
>
>
>               //return max != null ? NodeValue.makeNode(max): null;
>
>               return NodeValue.makeString(test);
>
>       }
>
> }
>
>
>
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TopBraid Composer Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/topbraid-composer-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to