另一个问题是neo4j-jdbc驱动程序。根据Rest api doc,有一种方法可以通过传递地图来创建节点:
Map<String, Object> props = new HashMap<String, Object>();
props.put( "name", "Andres" );
props.put( "position", "Developer" );
Map<String, Object> params = new HashMap<String, Object>();
params.put( "props", props );
String query = "CREATE ({props})";
engine.execute( query, params );
我必须创建一个具有很多属性的节点,然后我得到一个json。有没有办法创建像这样的节点
JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON(json);
Map<String, Object> map = (Map<String, Object>) JSONObject.toBean(jsonObject, Map.class);
...
connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("CREATE (n{1}");
preparedStatement.setObject(1, map);
preparedStatement.executeQuery();
Thanx all!
答案 0 :(得分:0)
具有多个属性的节点: -
Map<String, Object> courseNodeInfo=new HashMap<String, Object>();
courseNodeInfo.put("name",courseId);
courseNodeInfo.put("createtime",createTime);
courseNodeInfo.put("title",title);
courseNodeInfo.put("status", "draft");
courseNodeInfo.put("coursetype", courseType);
courseNodeInfo.put("sectionexist",isSectionExist);
courseNodeInfo.put("coverimage", "coursecover.jpg");
// TODO Auto-generated method stub
Connection connect = null;
int status = 00;
try {
connect = graphdbConnect();
//String insert = "CREATE (n:Test {1})";
String query = "CREATE (n:" + nodeLabel +"{1}) RETURN n";
query=query.toLowerCase();
try (PreparedStatement preparedStatement = connect.prepareStatement(query)){
preparedStatement.setObject(1,courseNodeInfo);
System.out.println(query+" ---> query");
preparedStatement.executeQuery();
status = ServerStatusReport.OK();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}