1

テーブルを .csv ファイルとして出力しようとしています。sqlite-jdbc Java ライブラリを使用してクエリを実行しています。声明は次のとおりです。

.mode csv
.output test.csv
select * from geninfo;
.output stdout

これは私のJavaコードです:

try {
            try {
                // create a database connection
                Class.forName("org.sqlite.JDBC");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(SQLite.class.getName()).log(Level.SEVERE, null, ex);
            }
            connection = DriverManager.getConnection("jdbc:sqlite:702Data.db");
            Statement statement = connection.createStatement();
            statement.setQueryTimeout(30);  // set timeout to 30 sec.
            statement.executeUpdate("create table if not exists geninfo (id TEXT, DeviceID TEXT)");
            statement.executeUpdate(".mode csv");
            statement.executeUpdate(".output test.csv");
            statement.executeUpdate("select * from geninfo;");
            statement.executeUpdate(".output stdout");

            ResultSet rs = statement.executeQuery("select * from geninfo");
            while (rs.next()) {
                // read the result set
                System.out.println("DeviceID = " + rs.getString("DeviceID"));
                System.out.println("id = " + rs.getInt("id"));
            }
        } catch (SQLException e) {
            // if the error message is "out of memory", 
            // it probably means no database file is found
            System.err.println(e.getMessage());
        } finally {
            try {
                if (connection != null) {
                    connection.close();
                }
            } catch (SQLException e) {
                // connection close failed.
                System.err.println(e);
            }
        }
    }

ピリオドの周りに括弧を追加し、ピリオドを削除しようとしましたが、どちらも同じ構文エラーを引き起こします。

4

1 に答える 1