提交 d9a6021c 编写于 作者: S Shiny

更新内容

上级 a34280ac
{
"node_id": "neo4j-0261ccb903994df281a2ec606b5d8c9e",
"keywords": [],
"children": [
{
"什么是图数据库": {
"keywords": [
"图数据库"
],
"children": [
{
"图论": {
"keywords": [
"节点",
"边",
"关系"
],
"children": []
}
},
{
"RDF": {
"keywords": [],
"children": []
}
},
{
"属性图": {
"keywords": [],
"children": []
}
},
{
"原生图": {
"keywords": [
],
"children": []
}
}
]
},
"什么时候需要图数据库": {
"keywords": [
"图数据库"
],
"children": []
},
"Neo4j 图数据库概览": {
"keywords": [
"图数据库"
],
"children": []
}
}
],
"keywords": ["数据库", "图数据库"],
"children": [],
"export": [
"helloworld.md"
"databases.json"
]
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "helloworld.md",
"author": "shiny",
"source": "databases.md",
"notebook_enable": false
}
\ No newline at end of file
# 数据库的分类
当代数据库发展有如下几种。
## 答案
关系型数据库 RDBMS
文档数据库
时序数据库
图数据库 Graph Database
## 选项
### A
关系型数据库 RDBMS
### B
文档数据库
### C
时序数据库
### D
图数据库 Graph Database
\ No newline at end of file
# Hello World
Neo4J 可以通过 shell 直接写查询语句,也可以在 Java、Python 等语言中创建连接查询,以下哪个查询<span style="color:red">不是</span>图数据库 Neo4J 的查询?
## 答案
```sql
SELECT name FROM Person
LEFT JOIN Person_Department
ON Person.Id = Person_Department.PersonId
LEFT JOIN Department
ON Department.Id = Person_Department.DepartmentId
WHERE Department.name = "IT Department"
```
## 选项
### MySQL查询
```sql
MATCH (p:Person)-[:WORKS_AT]->(d:Dept)
WHERE d.name = "IT Department"
RETURN p.name
```
### 使用JDBC查询Neo4J
```java
Connection con = DriverManager.getConnection("jdbc:neo4j://localhost:7474/");
String query =
"MATCH (:Person {name:{1}})-[:EMPLOYEE]-(d:Department) RETURN d.name as dept";
try (PreparedStatement stmt = con.prepareStatement(QUERY)) {
stmt.setString(1,"John");
ResultSet rs = stmt.executeQuery();
while(rs.next()) {
String department = rs.getString("dept");
....
}
}
```
### 在Python中查询
```python
from neo4j import GraphDatabase
class HelloWorldExample:
def __init__(self, uri, user, password):
self.driver = GraphDatabase.driver(uri, auth=(user, password))
def close(self):
self.driver.close()
def print_greeting(self, message):
with self.driver.session() as session:
greeting = session.write_transaction(self._create_and_return_greeting, message)
print(greeting)
@staticmethod
def _create_and_return_greeting(tx, message):
result = tx.run("CREATE (a:Greeting) "
"SET a.message = $message "
"RETURN a.message + ', from node ' + id(a)", message=message)
return result.single()[0]
if __name__ == "__main__":
greeter = HelloWorldExample("bolt://localhost:7687", "neo4j", "password")
greeter.print_greeting("hello, world")
greeter.close()
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册