2014-02-09 32 views
1

另一個問題aboit neo4j-jdbc驅動程序。根據REST API文檔有通過將地圖以創建節點的方式:Neo4j-jdbc散列表或json在準備語句中

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

謝謝大家!

+0

似乎是一個問題。 neo4j的谷歌集團的問題。 https://groups.google.com/forum/#!topic/neo4j/2kEfVieckUI – 0pipe0

回答

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