All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.inria.edelweiss.kgenv.eval.SQLFun Maven / Gradle / Ivy

Go to download

Corese is a Semantic Web Factory (triple store and SPARQL endpoint) implementing RDF, RDFS, SPARQL 1.1 Query and Update.

There is a newer version: 3.3.3
Show newest version
package fr.inria.edelweiss.kgenv.eval;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import fr.inria.acacia.corese.api.IDatatype;

public class SQLFun {
	
	static final String DERBY_DRIVER = "org.apache.derby.jdbc.ClientDriver";
	static Object driver;

	public ResultSet sql(IDatatype uri, IDatatype dd,
			IDatatype login, IDatatype passwd, IDatatype query){
		if (driver == null){
			// first time
			try {
				// remember driver is loaded
				driver = Class.forName(dd.getLabel()).newInstance();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return sql(uri, login, passwd, query);
	}
	
	public ResultSet sql(IDatatype uri, 
			IDatatype login, IDatatype passwd, IDatatype query){
		try {
			if (driver == null){ 
				try {
					// default is derby
					driver = Class.forName(DERBY_DRIVER).newInstance();
				} catch (InstantiationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
        	Connection con = 
        		DriverManager.getConnection(uri.getLabel(), login.getLabel(), passwd.getLabel());
        	Statement stmt = con.createStatement();
        	ResultSet rs = stmt.executeQuery(query.getLabel());
        	return rs;
        }
        catch (SQLException e) {
        	// TODO Auto-generated catch block
        	e.printStackTrace();
        }  
        return null;
	}
	
	
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy