如何从Java执行多个相关的SQLite查询(运行SQLite脚本)?

时间:2017-12-05 03:23:08

标签: java sqlite

我在SQLite数据库中有一些数据。 SQLiteBrowser中的以下查询完全给出了我想要的ResultSet:

With TempTable0 AS (SELECT Source, Date, Value AS Close FROM FinData WHERE Type = 'Close'),
TempTable1 AS (SELECT Source, Date, Value AS  Colume FROM FinData WHERE Type = ' Colume')

SELECT DISTINCT TempTable0.Date,  Close,   Colume  FROM TempTable0 
JOIN TempTable1 ON TempTable1.Date = TempTable0.Date 

现在,我尝试通过简单的executeQuery - Java方法将单个查询作为单个查询,并在Matrixlike-DataStructure中读取数据:

String sql = "With TempTable0 AS (SELECT Source, Date, Value AS Close FROM FinData WHERE Type = 'Close'), TempTable1 AS (SELECT Source, Date, Value AS  Colume FROM FinData WHERE Type = ' Colume') SELECT DISTINCT TempTable0.Date,  Close,   Colume  FROM TempTable0 JOIN TempTable1 ON TempTable1.Date = TempTable0.Date";

Connection Conn = DriverManager.getConnection(SQLCommunication.urlDB);
Statement stmt = Conn.createStatement();

ResultSet rs = stmt.executeQuery(sql);

while (rs.next() ) {

    String res = rs.getString("Close");
    DataMatrix.get("Close").add(res);

    res = rs.getString("Colume");
    DataMatrix.get("Colume").add(res);

    }

但是,Resultset返回null。 我怀疑这是因为它无法使用两个依赖的SQLite-Queries,但是,我不知道如何解决这个问题。

我不是SQLite和Java交互的专家,而且我现在真的没有想法了。你有任何吸烟吗? (甚至可能会将这两个语句嵌套在一个中,以便一次性执行它?)

非常感谢!

Wiwi

0 个答案:

没有答案