SQLite 连接字符串配置
我的系统桌面上有一个名为 localEntry.sqlite 的 SQLite 数据库文件。我想读取该数据库的其中一张表的数据。为此,我在 Eclipse 中编写了一段代码来访问其中一个表中的所有数据:
public class SqliteDbRead {
private static String col1;
private static String col2;
public static void main(String[] args) throws
SQLException, ClassNotFoundException {
//Get Connection
Class.forName("org.sqlite.JDBC");
Connection con = DriverManager.getConnection("jdbc:sqlite:localEntry.sqlite");
//obtain a statement
Statement st = con.createStatement();
String query = "select * from submitted_table";
//Execute Query
ResultSet rs = st.executeQuery(query);
while (rs.next()) {
col1 = rs.getString("col1");
col2 = rs.getString("col2");
} //while
con.close();
} //main
}
当 localEntry.sqlite 文件位于我的 JavaProject 中时,此代码可以正常工作。如果此数据库文件位于桌面或计算机中的其他位置,我不知道连接字符串(或任何其他方法)是什么。
I have a SQLite database file with name localEntry.sqlite on my Desktop of the system. I want to read the data of one of the table of this database. For this I write a code in Eclipse to access all the data form one of the table.:
public class SqliteDbRead {
private static String col1;
private static String col2;
public static void main(String[] args) throws
SQLException, ClassNotFoundException {
//Get Connection
Class.forName("org.sqlite.JDBC");
Connection con = DriverManager.getConnection("jdbc:sqlite:localEntry.sqlite");
//obtain a statement
Statement st = con.createStatement();
String query = "select * from submitted_table";
//Execute Query
ResultSet rs = st.executeQuery(query);
while (rs.next()) {
col1 = rs.getString("col1");
col2 = rs.getString("col2");
} //while
con.close();
} //main
}
This code work fine when the localEntry.sqlite file is in my JavaProject. Here I don't know what is connection string (or any other method) if this database file is on Desktop or on other place in computer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个问题,它有一个到Windows机器的D驱动器的连接字符串: 如何将SQLite与Java连接?
Take a look at this question, it has a connection string to the D-Drive of a windows machine: How to connect SQLite with Java?