private void saveToStore(String rdfFileName) throws ClassNotFoundException, IOException { String M_DBDRIVER_CLASS = "com.mysql.jdbc.Driver"; // load the the driver class Class.forName(M_DBDRIVER_CLASS); String dbUrl = "jdbc:mysql://" + hostName + "/" + dbName; // create a database connection IDBConnection conn = new DBConnection(dbUrl, userName, password, "MySQL"); // create a model maker with the given connection parameters ModelMaker maker = ModelFactory.createModelRDBMaker(conn); ModelRDB model = (ModelRDB) maker.openModel(modelName); InputStream file = new FileInputStream(rdfFileName); model.read(file,null,"N3"); file.close(); }
/** * <p>Method that returns a new or an existing Jena RDB model</p> * @param dbUrl - the database url * @param dbUser - the database user * @param dbPass - the database password * @param dbType - the database type * @param create - true iff a new model is to be created, false otherwise * @return a new or an existing Jena RDB model */ public Model getRDBModel( String dbUrl, String dbUser, String dbPass, String dbType, boolean create ) { //Create a database model maker ModelMaker rdbModelMaker = ModelFactory.createModelRDBMaker( new DBConnection( dbUrl, dbUser, dbPass, dbType ) ); //If the model does not exist create a new model, else return the existing model if( !rdbModelMaker.hasModel( "rdbModel" ) ) { if ( create ) return rdbModelMaker.createModel( "rdbModel" ); else return null; } else return rdbModelMaker.openModel( "rdbModel" ); }
private static ModelMaker getFileModelMaker(String filename) { return com.hp.hpl.jena.rdf.model.ModelFactory.createFileModelMaker(filename); }