-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathsampleSQLNoSQL.py
More file actions
34 lines (24 loc) · 1 KB
/
sampleSQLNoSQL.py
File metadata and controls
34 lines (24 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import jpype
import jpype.dbapi2
jpype.startJVM(classpath=["./gridstore.jar", "./gridstore-arrow.jar", "./gridstore-jdbc.jar"])
import griddb_python as griddb
import sys
### SQL create table/insert
url = "jdbc:gs://127.0.0.1:20001/myCluster/public"
conn = jpype.dbapi2.connect(url, driver="com.toshiba.mwcloud.gs.sql.Driver",
driver_args={"user":"admin", "password":"admin"})
curs = conn.cursor()
curs.execute("DROP TABLE IF EXISTS Sample")
curs.execute("CREATE TABLE IF NOT EXISTS Sample ( id integer PRIMARY KEY, value string )")
print('SQL Create Table name=Sample')
curs.execute("INSERT INTO Sample values (0, 'test0'),(1, 'test1'),(2, 'test2'),(3, 'test3'),(4, 'test4')")
print('SQL Insert')
### NoSQL select
factory = griddb.StoreFactory.get_instance()
gridstore = factory.get_store(host="127.0.0.1", port=10001, cluster_name="myCluster", username="admin", password="admin")
col = gridstore.get_container("Sample")
q = col.query("select *")
rs = q.fetch()
while rs.has_next():
row = rs.next()
print(row)