【发布时间】:2017-01-14 03:16:12
【问题描述】:
我想将字符串参数插入到 Java 中的密码查询中。下面是我使用的代码,我有一个名为“piyumi”的人员节点,我想与一个活动节点建立关系。活动节点的名称是'walking'。当我执行代码时,我得到 http 状态码 400。谁能帮我修改密码查询,以便我可以插入字符串变量 s 而不会出错。
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import javax.ws.rs.core.MediaType;
public class NeoAPIClass {
private final String baseUri = "http://localhost:7474/db/data/cypher";
private final String user = "neo4j";
private final String password = "12345";
public static void main(String args[]) throws JSONException {
NeoAPIClass n=new NeoAPIClass();
n.runQuery();
}
void runQuery() throws JSONException {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter(user, password));
WebResource cypherResource = client.resource(baseUri);
String s="walking";
JSONObject obj = new JSONObject();
obj.put("query", "Match(piyumi : Person{name:\"Piyumi\"}) create (piyumi)-[:doing{timestamp:4789}]->(n:activity) WHERE n.name=s");
String st = obj.toString();
ClientResponse cypherResponse = cypherResource.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON_TYPE).entity(st).post(ClientResponse.class);
System.out.println("Output from Server .... "+ cypherResponse.getStatus());
}
}
【问题讨论】:
标签: java neo4j cypher graph-databases