参见英文答案 > How to list the tables in a SQLite database file that was opened with ATTACH? 17个
我是sqlite的新手.我正在Eclipse(Java)中使用它,以防这是相关的.
现在我的问题是我有一个* .db文件,对其内容一无所知.我想知道哪种方式可以获得有关内部表格的一些信息.否则,通过SELECT Query正确读取数据库似乎是不可能的.所以基本上我的问题只是这一部分
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * FROM ???????;" );
while ( rs.next() ) {
int id = rs.getInt("id");
..
解决方法:
1.了解数据库的架构
在.db文件的位置打开终端.
输入以下命令以启动sqlite控制台.
sqlite3 NameOfDatabase.db
1.1所有表格
然后将以下命令提供给控制台:
.schema
这将为您提供所有表格所需的所有信息,包括字段的数据类型.换句话说,上面的命令会给你,你的database schema
.
上述命令的输出示例如下:
CREATE TABLE log (ID INTEGER PRIMARY KEY AUTOINCREMENT, userID INTEGER, cardID INTEGER, eventID INTEGER, nameOnTicket TEXT, pricePaid REAL);
CREATE TABLE card (cardID INTEGER PRIMARY KEY AUTOINCREMENT, cardNum TEXT, securityCode TEXT, expiryMonth INTEGER, expiryYear INTEGER, addressID INTEGER, userID INTEGER);
它实际上返回了重新创建表的命令,因此如果您想输出查询以重新创建表或为数据库/应用程序创建文档,那么这也很方便,但也要了解结构和数据库表.
1.2具体表格
此外,您可以使用以下命令查看特定表的架构:
.schema TableName
这将返回TableName表的模式.
2.将sqlite与Eclipse集成
另一种选择是将您的sqlite数据库与Eclipse集成,您可以找到执行此操作的步骤.以下步骤已从官方Eclipse维基中复制,您可以找到here.
1) Download the sqlite drivers from 07002. The actual zip file with the
driver is at 07003. Expand the zip somewhere locally and note the
location.2) Put the sqlite_jni.dll from the zip into your JRE’s bin directory.
The driver requires this file to be in the java library path.3) In Eclipse with DTP 1.0 installed (preferably the final build or a
nightly build dated 110806 or later), go to the Preferences
(Window->Preferences) and select the Connectivity->Driver DeFinitions
page.4) Select the “Generic JDBC” category in the Available Driver
DeFinitions tree and click “Add…”.5) Select “Generic JDBC Driver->Generic JDBC Driver” in the Available
Driver Templates tree. Give the new generic JDBC driver a name like
“javasqlite JDBC driver”. Click OK.6) Click “Add Jar/Zip” and select the sqlite.jar from the driver zip
you expanded in step 1. Click Open.7) In the Properties table, select the Driver Class property and click
the “…” button. If the jar is accessible, you will see a dialog
appear with at lease one class in the list. Select
“sqlite.JDBCDriver”. Click OK.8) Also in the Properties table, select the Driver URL property and
type the following: jdbc:sqlite:/DRIVE:/dirA/dirB/dbfile9) Click OK on the Edit Driver DeFinition dialog. You should see your
new driver appear in the driver list on the Driver DeFinitions
preference page.10) Click OK to close the Preferences dialog.
11) If the Data Source Explorer is not open, open the
Connectivity->Data Source Explorer view from the Window->Show View
menu or open the Database Development perspective from the
Window->Open Perspective.12) In the Data Source Explorer, right-click on the Databases category
and select New…13) In the New Connection Profile wizard’s Wizard Selection Page,
choose the sql Model-JDBC Connection entry in the list and click Next.14) Give your new profile a name like “sqliteTestDB”. Click Next.
15) In the “Select a driver from the drop-down” combo Box, select your
new sqlite driver deFinition. Modify the file path in the sample URL
to match the path to your local sqlite database.16) Click “Test Connection” to verify you can connect to your
database.17) Click Finish to create the profile.
18) In the Data Source Explorer, right-click on the new profile and
select Connect. You should see content appear in the tree beneath the
profile. browse through your database to view available tables and
their columns.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。