matlab 2019操作 sqlite有两种方式
从上面可以知道JDBC方式功能多于直接连接。
帮助文档说下载驱动,但是不用下载JDBC驱动,已经自带!
升级驱动办法,从下面网站下载,覆盖 安装目录\Polyspace\R2019b\java\jar\polyspace 下的sqlite-jdbc.jar,重启matlab即可,
文件下载链接
- Release versions: Download or Maven https://oss.sonatype.org/content/repositories/releases/org/xerial/sqlite-jdbc/
- Latest snapshot (pre-release) versions are also available: https://oss.sonatype.org/content/repositories/snapshots/org/xerial/sqlite-jdbc/
JDBC方式连接tt.db办法
conn = database('tt.db','','','org.sqlite.JDBC','jdbc:sqlite:完整路径/tt.db')
第一个参数为数据库文件名字
注意最后一个参数为 完整路径!
conn =
connection - 属性:
DataSource: 'tt.db'
UserName: ''
Driver: 'org.sqlite.JDBC'
URL: 'jdbc:sqlite:E:\...'
Message: ''
Type: 'JDBC Connection Object'
Database Properties:
AutoCommit: 'on'
ReadOnly: 'off'
LoginTimeout: 0
MaxDatabaseConnections: 0
Catalog and Schema Information:
DefaultCatalog: ''
Catalogs: {}
Schemas: {}
Database and Driver Information:
DatabaseProductName: 'SQLite'
DatabaseProductVersion: '3.32.3'
DriverName: 'SQLite JDBC'
DriverVersion: '3.32.3.2'
从ts表中获取全部数据
sqlquery = 'SELECT * FROM ts';
results = fetch(conn,sqlquery)
results =
4×3 table
t1 t2 t3
__ ___ ________________________________________________
1 1 {'12222222222223333333333333333333333444444444'}
2 22 {'33' }
3 333 {'111' }
4 444 {'555' }
关闭数据库
close(conn)
参考
https://www.mathworks.com/help/database/ug/sqlite-jdbc-windows.html