【问题标题】:Neo4j-jdbc hashmap or json in prepared statement准备好的语句中的 Neo4j-jdbc hashmap 或 json
【发布时间】:2014-02-09 16:42:51
【问题描述】:

关于 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();

谢谢大家!

【问题讨论】:

标签: java jdbc neo4j cypher


【解决方案1】:

具有多个属性的节点:-

 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();
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-12
    • 2013-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多