Java 如何从jdbc读取sqllite文件
我正在尝试将我的mozilla firefox历史记录存储到一个文本文件中并保存它 这是我的节目Java 如何从jdbc读取sqllite文件,java,sqlite,jdbc,Java,Sqlite,Jdbc,我正在尝试将我的mozilla firefox历史记录存储到一个文本文件中并保存它 这是我的节目 Connection c = null; Statement stmt = null; try { // create new file Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:test.db");
Connection c = null;
Statement stmt = null;
try {
// create new file
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:test.db");
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * FROM COMPANY;" );
据我所知,它将从测试数据库中的公司表中获取数据
但是我想从文件places.sqllite中获取数据,并将其内容存储到普通文本文件中
如果您对更好的方法有任何建议,我们将不胜感激。您创建了一个test.db,表名为company。尝试更改数据库的属性首先使用此类
org.sqlite.SQLiteDataSource
org.sqlite.SQLiteJDBCLoader
从JDBC
驱动程序中使用sqlite
(使用JDBC)如下
BufferedWriter writer = Files.newBufferedWriter(Paths.get(filePath))
SQLiteDataSource dataSource = new SQLiteDataSource();
dataSource.setUrl("jdbc:sqlite:/path/to/places.sqllite");
ResultSet executeQuery = dataSource.getConnection().createStatement().executeQuery("select * from table;");
while (executeQuery.next()) {
writer.write(executeQuery.getMetaData().getColumnLabel(i));
}
“它将从测试数据库中的公司表中删除数据”--抱歉,你能解释一下这意味着什么吗?请看一看编辑的内容…….newBufferedWriter方法需要3个参数…..什么是filepath?它是我们要写入的文件的路径还是任何其他路径?
newBufferedWriter
方法实际上需要2
个参数,但不用担心,filepath
是从Sqlite
表中存储内容的txt
文件的路径,在此之前请创建文件txtfile.txt
并像下面这样使用path.get(“path/to/txtfile.txt”)
。