我有以下问题:
当我尝试将文件的内容加载到模型中时,它会引发异常,但我不知道为什么会引发异常,并且它会交付大量带有语法错误的SQL。
有人可以帮我吗?
我检查了jdbc连接,但似乎还可以。
我将1.3.5 Jena SDB与play 2.2.0结合使用。然后,应使用mode =“ mysql”的模式将模型持久化到h2数据库。
引发异常的代码:
ds = SDBFactory.connectDataset(store);
Logger.debug("load default model");
model = ds.getDefaultModel();
Logger.debug("Loaded model");
FileManager.get().readModel(
model,
new File(rdfFile.getParentFile().getCanonicalPath()
.concat("/dataversions/" + datasetName)
+ ".txt").getCanonicalPath(), "N-TRIPLES");
Logger.debug("Filemanager loaded file into model...");
和抛出的异常:
[debug] application - Create the new Dataset: test
[debug] application - load default model
[debug] application - Loaded model
[error] c.h.h.j.s.l.LoaderTuplesNodes - Error in thread: Problem making new tupleloader
com.hp.hpl.jena.sdb.SDBException: Problem making new tupleloader
at com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes.updateOneTuple(LoaderTuplesNodes.java:292) ~[jena-sdb-1.3.5.jar:1.3.5]
at com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes.access$200(LoaderTuplesNodes.java:43) ~[jena-sdb-1.3.5.jar:1.3.5]
at com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes$Commiter.run(LoaderTuplesNodes.java:362) ~[jena-sdb-1.3.5.jar:1.3.5]
at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.GeneratedConstructorAccessor18.newInstance(Unknown Source) ~[na:na]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_45]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_45]
at com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes.updateOneTuple(LoaderTuplesNodes.java:288) ~[jena-sdb-1.3.5.jar:1.3.5]
at com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes.access$200(LoaderTuplesNodes.java:43) ~[jena-sdb-1.3.5.jar:1.3.5]
at com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes$Commiter.run(LoaderTuplesNodes.java:362) ~[jena-sdb-1.3.5.jar:1.3.5]
Caused by: com.hp.hpl.jena.sdb.SDBException: Problem initialising loader for [Triples]
at com.hp.hpl.jena.sdb.layout2.TupleLoaderBase.<init>(TupleLoaderBase.java:59) ~[jena-sdb-1.3.5.jar:1.3.5]
at com.hp.hpl.jena.sdb.layout2.hash.TupleLoaderHashBase.<init>(TupleLoaderHashBase.java:29) ~[jena-sdb-1.3.5.jar:1.3.5]
at com.hp.hpl.jena.sdb.layout2.hash.TupleLoaderHashMySQL.<init>(TupleLoaderHashMySQL.java:29) ~[jena-sdb-1.3.5.jar:1.3.5]
at sun.reflect.GeneratedConstructorAccessor18.newInstance(Unknown Source) ~[na:na]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_45]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_45]
Caused by: org.h2.jdbc.JdbcSQLException: Syntax Fehler in SQL Befehl "CREATE TEMPORARY TABLE NNODETRIPLES
(N0 BIGINT ,
N1 LONGTEXT BINARY[*] CHARACTER SET UTF8 ,
N2 VARCHAR(10) BINARY CHARACTER SET UTF8 ,
N3 VARCHAR(200) BINARY CHARACTER SET UTF8 ,
N4 INT
) ENGINE=MYISAM "; erwartet "(, FOR, UNSIGNED, NOT, NULL, AS, DEFAULT, GENERATED, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFA
ULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ,, )"
Syntax error in SQL statement "CREATE TEMPORARY TABLE NNODETRIPLES
(N0 BIGINT ,
N1 LONGTEXT BINARY[*] CHARACTER SET UTF8 ,
N2 VARCHAR(10) BINARY CHARACTER SET UTF8 ,
N3 VARCHAR(200) BINARY CHARACTER SET UTF8 ,
N4 INT
) ENGINE=MYISAM "; expected "(, FOR, UNSIGNED, NOT, NULL, AS, DEFAULT, GENERATED, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFA
ULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ,, )"; SQL statement:
CREATE TEMPORARY TABLE NNodeTriples
(n0 BIGINT ,
n1 LONGTEXT BINARY CHARACTER SET utf8 ,
n2 VARCHAR(10) BINARY CHARACTER SET utf8 ,
n3 VARCHAR(200) BINARY CHARACTER SET utf8 ,
n4 INT
) ENGINE=MYISAM [42001-172]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) ~[h2.jar:1.3.172]
at org.h2.message.DbException.get(DbException.java:169) ~[h2.jar:1.3.172]
at org.h2.message.DbException.getSyntaxError(DbException.java:194) ~[h2.jar:1.3.172]
at org.h2.command.Parser.getSyntaxError(Parser.java:491) ~[h2.jar:1.3.172]
at org.h2.command.Parser.read(Parser.java:2822) ~[h2.jar:1.3.172]
at org.h2.command.Parser.readIfMore(Parser.java:809) ~[h2.jar:1.3.172]
[error] c.h.h.j.s.l.LoaderTuplesNodes - Error in thread: Problem making new tupleloader
com.hp.hpl.jena.sdb.SDBException: Problem making new tupleloader
at com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes.updateOneTuple(LoaderTuplesNodes.java:292) ~[jena-sdb-1.3.5.jar:1.3.5]
at com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes.access$200(LoaderTuplesNodes.java:43) ~[jena-sdb-1.3.5.jar:1.3.5]
at com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes$Commiter.run(LoaderTuplesNodes.java:362) ~[jena-sdb-1.3.5.jar:1.3.5]
at java.lang.Thread.run(Thread.java:744) [na:1.7.0_45]
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.GeneratedConstructorAccessor18.newInstance(Unknown Source) ~[na:na]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_45]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_45]
at com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes.updateOneTuple(LoaderTuplesNodes.java:288) ~[jena-sdb-1.3.5.jar:1.3.5]
at com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes.access$200(LoaderTuplesNodes.java:43) ~[jena-sdb-1.3.5.jar:1.3.5]
at com.hp.hpl.jena.sdb.layout2.LoaderTuplesNodes$Commiter.run(LoaderTuplesNodes.java:362) ~[jena-sdb-1.3.5.jar:1.3.5]
Caused by: com.hp.hpl.jena.sdb.SDBException: Problem initialising loader for [Triples]
at com.hp.hpl.jena.sdb.layout2.TupleLoaderBase.<init>(TupleLoaderBase.java:59) ~[jena-sdb-1.3.5.jar:1.3.5]
at com.hp.hpl.jena.sdb.layout2.hash.TupleLoaderHashBase.<init>(TupleLoaderHashBase.java:29) ~[jena-sdb-1.3.5.jar:1.3.5]
at com.hp.hpl.jena.sdb.layout2.hash.TupleLoaderHashMySQL.<init>(TupleLoaderHashMySQL.java:29) ~[jena-sdb-1.3.5.jar:1.3.5]
at sun.reflect.GeneratedConstructorAccessor18.newInstance(Unknown Source) ~[na:na]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_45]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_45]
Caused by: org.h2.jdbc.JdbcSQLException: Syntax Fehler in SQL Befehl "CREATE TEMPORARY TABLE NNODETRIPLES
(N0 BIGINT ,
N1 LONGTEXT BINARY[*] CHARACTER SET UTF8 ,
N2 VARCHAR(10) BINARY CHARACTER SET UTF8 ,
N3 VARCHAR(200) BINARY CHARACTER SET UTF8 ,
N4 INT
) ENGINE=MYISAM "; erwartet "(, FOR, UNSIGNED, NOT, NULL, AS, DEFAULT, GENERATED, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFA
ULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ,, )"
Syntax error in SQL statement "CREATE TEMPORARY TABLE NNODETRIPLES
(N0 BIGINT ,
N1 LONGTEXT BINARY[*] CHARACTER SET UTF8 ,
N2 VARCHAR(10) BINARY CHARACTER SET UTF8 ,
N3 VARCHAR(200) BINARY CHARACTER SET UTF8 ,
N4 INT
) ENGINE=MYISAM "; expected "(, FOR, UNSIGNED, NOT, NULL, AS, DEFAULT, GENERATED, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFA
ULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ,, )"; SQL statement:
CREATE TEMPORARY TABLE NNodeTriples
(n0 BIGINT ,
n1 LONGTEXT BINARY CHARACTER SET utf8 ,
n2 VARCHAR(10) BINARY CHARACTER SET utf8 ,
n3 VARCHAR(200) BINARY CHARACTER SET utf8 ,
n4 INT
) ENGINE=MYISAM [42001-172]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) ~[h2.jar:1.3.172]
at org.h2.message.DbException.get(DbException.java:169) ~[h2.jar:1.3.172]
at org.h2.message.DbException.getSyntaxError(DbException.java:194) ~[h2.jar:1.3.172]
at org.h2.command.Parser.getSyntaxError(Parser.java:491) ~[h2.jar:1.3.172]
at org.h2.command.Parser.read(Parser.java:2822) ~[h2.jar:1.3.172]
at org.h2.command.Parser.readIfMore(Parser.java:809) ~[h2.jar:1.3.172]
编辑:
这行代码必须更改:
StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash, DatabaseType.H2);
最佳答案
H2无法理解MySQL语法,例如ENGINE=MYISAM
。每个SQL语法都不同。您需要告诉SDB它正在使用H2数据库。
关于java - Jena SDB将文件读入模型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20021869/