zoukankan      html  css  js  c++  java
  • java连接neo4j

    import java.sql.Connection;

    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import com.google.gson.JsonObject;
    import com.google.gson.JsonParser;

    import org.neo4j.jdbc.Driver;
    //Class.forName("org.neo4j.jdbc.Driver");
    //Connect

    public class DBUtil {
    Connection con;
    Statement stmt;
    ResultSet rs;
    public ResultSet rs(String sqlstring) throws SQLException {

    try {
    Class.forName("org.neo4j.jdbc.Driver").newInstance();
    this.con = DriverManager.getConnection("jdbc:neo4j:http://localhost:7474/","用户名","密码");
    this.stmt = con.createStatement();
    this.rs = stmt.executeQuery(sqlstring);
    } catch (InstantiationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    return rs;
    }
    public void close () {
    if (this.rs != null) {
    try {
    this.rs.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }

    if (this.stmt != null) {
    try {
    this.stmt.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }

    if (this.con != null) {
    try {
    this.con.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }
    public static void main(String[] args) throws SQLException {
    // TODO Auto-generated method stub
    DBUtil db=new DBUtil();
    ResultSet rs=db.rs("match (n) return n limit 10");
    while(rs.next())
    {
    String jsonstring=rs.getString("n");
    System.out.println(jsonstring);
    JsonObject jsonObject = (JsonObject) new JsonParser().parse(jsonstring);
    System.out.println(jsonObject.get("ff"));
    }
    db.close();
    }
    }

  • 相关阅读:
    vsftpd用户登陆目录
    Linux下能否用用apache运行ASP.NET的WebService
    rose软件下载(Rational Rose 2003 Enterprise Edition)
    linux删除目录
    2013314 生活日记
    ubuntu12.10安装GTK+
    SqlServer 基础知识数据检索、查询排序
    获取时间段:本周、本月、本年
    二、自定义控件之RadioButtonList
    ext.net 开发学习之FileUploadField与Image (四)
  • 原文地址:https://www.cnblogs.com/my---world/p/13946310.html
Copyright © 2011-2022 走看看