当我使用MySQL数据库系统和Jena2时,我得到了java.lang.NoSuchMethodError

时间:2013-04-23 14:26:12

标签: mysql jena

这是我的代码

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 线程“main”中的异常java.lang.NoSuchMethodError:com.hp.hpl.jena.rdf.model.ModelFactory.createModelRDBMaker(Lcom / hp / hpl / jena / db / IDBConnection;)Lcom / hp / hpl / jena / rdf /模型/ MM中;     在com.webservicecom.mysql.myontoly.main(myontoly.java:71))

1 个答案:

答案 0 :(得分:1)

这是耶拿的一个非常古老的版本。请使用current Jena distribution中的最新版本重试。