# -*- coding: utf-8 -*-
'''
Created on 2019年3月6日 @author: Administrator
'''
import sqlite3
import numpy as np
import json # 创建数据库连接对象
conn = sqlite3.connect('sample_database.db', isolation_level=None) # 连接到SQLite数据库
'''
参数isolation_level是同Conection.isolation_level的属性意义一样
'''
# 参数:memory:来创建一个内存数据库
# conn = sqlite3.connect(":memory:", isolation_level=None) x = np.arange(12).reshape(2, 6) # conn = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)
cursor = conn.cursor()
# 删除数据库表
cursor.execute("DROP TABLE test2")
# 创建数据库表
cursor.execute("create table test2 (arr BLOB)")
# 插入一行数据,numpy.array转List,json.dumps()函数是将字典转化为字符串
cursor.execute("insert into test2 (arr) values (?)", (json.dumps(x.tolist()),))
# 提交
conn.commit() cursor.execute("select arr from test2")
data = cursor.fetchall() print(data)
print(type(data)) # json.loads()函数是将字符串转化为字典
my_list = json.loads(data[0][0])
# List转numpy.array
temp = np.array(my_list)
print(temp)
print(type(temp)) cursor.close() # 关闭Cursor
conn.close() # 关闭数据库

最新文章

  1. PO VO DAO DTO BO TO概念与区别(转)
  2. github的使用步骤及体会
  3. rabbitMQ第四篇:远程调用
  4. uvalive4327(单调队列优化)
  5. 12.TCP的成块数据流
  6. Django__WSGI
  7. 简单介绍shell编程四剑客之grep
  8. 第一个SDL程序
  9. LGOJ P2921 [USACO08DEC]在农场万圣节Trick or Treat on the Farm
  10. python之GIL官方文档 global interpreter lock 全局解释器锁
  11. sql格式化并高亮
  12. linux bin & sbin different
  13. iOS webview加载时序和缓存问题总结
  14. 使用AOF持久化文件实现还原Redis数据库并得到RDB持久化文件
  15. Effective Java 第三版——61. 基本类型优于装箱的基本类型
  16. 使用Code First建模自引用关系笔记
  17. vSphere Replication:虚拟机的保护伞
  18. java集合的中的集合关系实现或继承关系图
  19. elasticsearch关于索引切分的实现
  20. 数据结构与算法JavaScript描述——列表

热门文章

  1. 在Java web模板的上进行编写
  2. logstash之OutPut插件
  3. ElasticSearch的介绍
  4. sqli-lab(16)
  5. 微信小程序打印json log
  6. CSS注
  7. php数组合并用加号(+)和用array_merge()的区别
  8. leetcode 441.排列硬币(python)
  9. 阶段3 1.Mybatis_07.Mybatis的连接池及事务_5 mybatis中使用poolead配置连接的原理分析
  10. 阶段3 1.Mybatis_06.使用Mybatis完成DAO层的开发_7 Mybatis中使用代理Dao的执行过程分析