when i Use MySQL Database System with Jena2,i got java.lang.NoSuchMethodError

非 Y 不嫁゛ 提交于 2020-01-07 06:24:27

问题


here is my code

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;

import com.hp.hpl.jena.db.DBConnection;
import com.hp.hpl.jena.db.IDBConnection;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.ModelMaker;

public class myontoly {

     public static final String MYSQL_DB_CLASSNAME = "com.mysql.jdbc.Driver";



        public static final String MYSQL_DB_URL =

           "jdbc:mysql://localhost:3306/mysql?useUnicode=true&characterEncoding=UTF8";



        public static final String MYSQL_DB_USER = "root";



        public static final String MYSQL_DB_PASSWD = "mysql2011510";



        public static final String DB = "MySQL";



        public static void main(String[] args) {

           //     loading the JDBC driver

           try {

               Class.forName(MYSQL_DB_CLASSNAME).newInstance();

           } catch (ClassNotFoundException e) {

               // TODO Auto-generated catch block

               e.printStackTrace();

           } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



           //Create database connection

           IDBConnection conn = new DBConnection(MYSQL_DB_URL, MYSQL_DB_USER, MYSQL_DB_PASSWD, DB);

           //Use the connection to create a model maker

           ModelMaker maker = ModelFactory.createModelRDBMaker(conn);

           Model base = maker.createDefaultModel();



           FileInputStream inputStreamfile = null;

           File file = new File("file:./Taxonomy.owl");

           try {

               inputStreamfile = new FileInputStream(file);

           } catch (FileNotFoundException e1) {

               // TODO Auto-generated catch block

               e1.printStackTrace();

           }

           InputStreamReader in = null;

           try {

               in =new InputStreamReader(inputStreamfile, "UTF-8");

           } catch (UnsupportedEncodingException e1) {

               // TODO Auto-generated catch block

               e1.printStackTrace();

           }

           base.read(in, null);

           try {

               in.close();

           } catch (IOException e1) {

               // TODO Auto-generated catch block

               e1.printStackTrace();

           }

           base.commit();

           //Close the database connection

           try {

               conn.close();

           } catch (SQLException e) {

               // TODO Auto-generated catch block

               e.printStackTrace();

           }
        }}

the error information,,and i tried jena 2.4, 2.6.4 Exception in thread "main" java.lang.NoSuchMethodError: com.hp.hpl.jena.rdf.model.ModelFactory.createModelRDBMaker(Lcom/hp/hpl/jena/db/IDBConnection;)Lcom/hp/hpl/jena/rdf/model/ModelMaker; at com.webservicecom.mysql.myontoly.main(myontoly.java:71))


回答1:


That's a very old version of Jena. Please try again with the latest version from the current Jena distribution.



来源:https://stackoverflow.com/questions/23930528/i-want-to-persist-the-rdf-model-in-mysql-using-jena

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!