文字列パラメータをJavaのCypherクエリに挿入したいとします。以下は私が使用したコードで、私は 'piyumi'という名前の人のノードを持っていて、アクティビティノードとの関係を作りたいと思っています。アクティビティノードの名前は「ウォーキング」です。コードを実行すると、httpのステータスコード400が得られます。誰も私がエラーなしで文字列変数を挿入できるように、サイファークエリを変更する手助けがあります。JavaコードのCypherクエリに文字列パラメータを挿入する際にエラーが発生しました
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());
}
}
ありがとうございました。 –