本文介绍了当我将MySQL数据库系统与Jena2一起使用时,出现java.lang.NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

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();

           }
        }}

错误信息,并且我尝试了jena 2.4、2.6.4线程主"中的异常java.lang.NoSuchMethodError:com.hp.hpl.jena.rdf.model.ModelFactory.createModelRDBMaker(Lcom/hp/hpl/jena/db/IDBConnection;)Lcom/hp/hpl/jena/rdf/model/ModelMaker; 在com.webservicecom.mysql.myontoly.main(myontoly.java:71))

the error information,,and i tried jena 2.4, 2.6.4Exception 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))

推荐答案

那是耶拿(Jena)的很旧的版本.请使用当前的Jena发行版中的最新版本重试.

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

这篇关于当我将MySQL数据库系统与Jena2一起使用时,出现java.lang.NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 05:42