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