0

下面的代码用于动态生成多个节点。我的 oracle 查询返回 12 行(表名)。但我只能在这里创建一个节点。无法创建 12 个节点。请帮忙。

public class Connect {
    static GraphDatabaseService db;
    public static void main(String[] args)    throws SQLException
    {
        db= new EmbeddedGraphDatabase("D:\\Neo_Database\\DB10" );
        DriverManager.registerDriver(new OracleDriver());
        Connection conn =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "hr", "hr");
        Statement stmt = conn.createStatement();
        ResultSet rset = stmt.executeQuery("select distinct segment_name table_name,segment_type from user_extents where segment_type='TABLE'");
        String table="";
        String segment="";
        Transaction tx = db.beginTx();
        while (rset.next()) {       
            table=rset.getString("table_name");        
            segment=rset.getString("segment_type");         
            Node datanode = db.createNode();
            datanode.setProperty("Schema", "HR");           
            createAndConnectNode( table, datanode,RelTypes.KNOWS );                
            tx.success();
        } 
        tx.finish(); 
    }  

    private static Node createAndConnectNode( String name, Node otherNode,
            RelationshipType relatiohshipType )
    {
        Node node = db.createNode();
        node.setProperty( name, name );
        node.createRelationshipTo( otherNode, relatiohshipType );
        System.out.println("name--------->"+name); 
        return node;
    }

    public static void registerShutdownHook(final GraphDatabaseService graphDb) {
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                graphDb.shutdown();
            }
        });
    }
}
4

0 回答 0