以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 Semantic Web(语义Web)/描述逻辑/本体 』  (http://bbs.xml.org.cn/list.asp?boardid=2)
----  请大家帮我解决这个问题吧,急啊1!  (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=60996)


--  作者:tuojia2001
--  发布时间:4/7/2008 10:55:00 AM

--  请大家帮我解决这个问题吧,急啊1!
我在用JENA将OWL文件导入Mysql数据库中时,出现一下错误:请大侠们帮我看看啊。
ERROR [main] (RDFDefaultErrorHandler.java:40) - Exception during database access
谢谢啊
--  作者:tuojia2001
--  发布时间:4/7/2008 11:03:00 AM

--  
请大侠们多多指教啊。谢谢了。
--  作者:jpz6311whu
--  发布时间:4/7/2008 11:10:00 AM

--  
请把完整的报错信息和程序代码贴出来看看
--  作者:tuojia2001
--  发布时间:4/7/2008 11:17:00 AM

--  
下面视我将owl导入mysql数据库的程序:
import java.io.*;
import com.hp.hpl.jena.db.*;
import com.hp.hpl.jena.rdf.model.*;

/**
*
*/
public class ImportPaper {

  /** MySQL driver classname */
  private static final String mysqlDriver = "com.mysql.jdbc.Driver";

  /** URL of database to use */
  private static final String DB_URL = "jdbc:mysql://localhost/test2?useUnicode=yes&characterEncoding=utf8";
  private static final String DB_TYPE = "MySQL";                            

  /** User credentials */
  private static final String DB_USER = "root";                      
  private static final String DB_PASSWORD = "ss";                     

  /** Name of the Jena model to create */
  private static final String MODEL_NAME = "test2";

  /** Locations of wordnet graphs to load */
  private static String FILE    = "document.owl";

  /**
   * Creates a MySQL backed model and reads the wordnet RDF files into it
   */
  public static void main(String args[]) {

    try {
      // Instantiate database driver
      Class.forName(mysqlDriver);                 
    } catch (ClassNotFoundException e) {
      System.err.println("MySQL driver class not found");
      System.exit(-1);
    }

    // Get a connection to the db
   DBConnection connection = new DBConnection(DB_URL, DB_USER, DB_PASSWORD, DB_TYPE);

    // Get a ModelMaker for database-backed models
    ModelMaker maker = ModelFactory.createModelRDBMaker(connection);

    // Create a new model named "document".
    Model paperModel = maker.createModel(MODEL_NAME,true);

    try {

      // Importing models inside a transaction helps performance.
      // Without this, the model each statement is auto-committed as it is
      // added.
      paperModel.begin();

      // Read each of the three WordNet documents into the model
      readFileIntoModel(FILE, paperModel);
      
      // Commit the transaction
      paperModel.commit();
      
    } catch (FileNotFoundException e) {

      System.err.println(e.toString());
    } finally {

      try {
        // Close the database connection
        connection.close();
      } catch (java.sql.SQLException e) {}
    }
  }

  /**
   * Reads RDF from a file into a model
   * @param filename Name of the RDF file to read
   * @param model The model to read the RDF into
   * @throws FileNotFoundException if the file can't be located on the classpath
   */
  private static void readFileIntoModel(String filename, Model model)
    throws FileNotFoundException {

      // Use the class loader to find the input file
      InputStream in = ImportPaper.class.getClassLoader().getResourceAsStream(filename);

      if (in == null) {
        throw new FileNotFoundException("File not found on classpath: "+ filename);
      }

      // Read the triples from the file into the model
      model.read(in,null);
    }
}
报错信息就只有ERROR [main] (RDFDefaultErrorHandler.java:40) - Exception during database access

我上网查感觉好像是字符编码的问题,可是实在视不知道具体怎么解决,
谢谢


--  作者:jpz6311whu
--  发布时间:4/7/2008 11:33:00 AM

--  
报错的完整stacktrace贴出来,报错信息太少了没办法帮你呀
--  作者:songjiesdnu
--  发布时间:2/26/2013 7:46:00 PM

--  请修改数据库中字段的编码
我也遇到同样的错误。最后发现是数据表字段编码的问题,因为jena自动创建的表的字段使用的是默认的latin编码,导致对于中文编码的文件不能写入到数据表中。你改一下表的字段编码类型就行了,我改成的是utf8的。你试试~~

以下是引用tuojia2001在2008-4-7 10:55:00的发言:
我在用JENA将OWL文件导入Mysql数据库中时,出现一下错误:请大侠们帮我看看啊。
ERROR [main] (RDFDefaultErrorHandler.java:40) - Exception during database access
谢谢啊


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
78.125ms