gpt4 book ai didi

java - apache tomcat 中的奇怪错误?

转载 作者:行者123 更新时间:2023-11-30 07:08:09 25 4
gpt4 key购买 nike

我正在使用带有 eclipse keplee 的 apache tomcat。这是我的 jsp 文件,它运行一个使用 sparql 从 tdb 查询的 java 文件。 jsp文件:

<%@ page import="check.test4query"  %>
<% test4query demo = new test4query();
test4query dem = new test4query();
String[] id =new String[20];
String[] dat =new String[20];
int i;
demo.mai("SELECT ?x WHERE { ?y <TO:> 'hjcooljohny75@gmail.com' . ?y <SUB:> ?x} LIMIT 20 ");
for(i=0;i<20;i++)
{ id[i]=test4query.arr[i];
id[i] = id[i].substring(0, Math.min(id[i].length(), 30));
}
for(i=0;i<20;i++)
{ //id[i]=test4query.arr[i];
out.println("<tr>"+"&nbsp&nbsp&nbsp&nbsp"+id[i]+"<hr style='border-color:#E6E6E6;padding:0px;margin:0px'>"+"</tr>");
}
%>

这是我的测试查询:

public static String[] arr=new String[20];
public void mai (String s) {
//String s;
//load the dataset
//String query1;
//query1="hjcooljohny75@gmail.com";
//query1 = (String)(subjectentry.getText());
// s="SELECT ?x WHERE { ?y <TO:> '"+query1+"' . ?y <SUB:> ?x} LIMIT 20 ";
System.out.println(s);
String directory = "EMAILADDRESS" ;
Dataset ds = TDBFactory.createDataset(directory) ;
Model model = ds.getDefaultModel() ;
ds.begin(ReadWrite.READ) ;
QueryExecution qExec = QueryExecutionFactory.create(s, ds) ;
int i=0;
try{
ResultSet rs = qExec.execSelect() ;
String x=rs.toString();



while (rs.hasNext()) {
QuerySolution qs = rs.next();
String rds;
if(qs.get("x")!=null)
rds = qs.get("x").toString();
else rds="hi";
// String em = (String)rs.getString();
if(rds==null)
break;
//System.out.println(rds);
arr[i] = rds;
i++;
//for (int i =0; i < arr.length; i++){


}
} finally
{qExec.close() ;
ds.commit();
ds.end();
}
for( i=0;i<20;i++)
System.out.println(arr[i]);
//arr[0]="hi";


// return arr;
// try {


// ResultSetFormatter.out(rs) ;
// } finally { qExec.close() ; }

// Another query - same view of the data.

}

问题是当我启动 tomcat 服务器时它运行完美显示结果但是之后如果我刷新页面它显示错误:

com.hp.hpl.jena.tdb.transaction.TDBTransactionException: Not in a transaction
com.hp.hpl.jena.tdb.transaction.DatasetGraphTransaction.get(DatasetGraphTransaction.java:106)
com.hp.hpl.jena.tdb.transaction.DatasetGraphTransaction.get(DatasetGraphTransaction.java:40)
com.hp.hpl.jena.sparql.core.DatasetGraphTrackActive.getDefaultGraph(DatasetGraphTrackActive.java:91)
com.hp.hpl.jena.sparql.core.DatasetImpl.getDefaultModel(DatasetImpl.java:103)
check.test4query.mai(test4query.java:59)
org.apache.jsp.grayscale.gmail_005flike_jsp._jspService(gmail_005flike_jsp.java:210)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

这一直都在发生,但是当我重新启动服务器时,它第一次显示正确的答案,然后显示错误。我不知道问题出在哪里以及如何纠正??

最佳答案

这是错误的方式:

Model model = ds.getDefaultModel() ;
ds.begin(ReadWrite.READ) ;

改为尝试:

ds.begin(ReadWrite.READ) ;
Model model = ds.getDefaultModel() ;

关于java - apache tomcat 中的奇怪错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24202703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com