Android プロジェクトの res/raw フォルダーに配置したファイルにアクセスしようとしています。この .CSV ファイルを使用してCsvJdbc jar を使用すると、データベースがあるかのようにクエリを実行できます。たとえば、InputStreamでそれを取得する多くの例を見てきました...
InputStream raw;
raw = getResources().openRawResource(R.raw.vehicles);
しかし、接続を作成してファイルを取得する必要があります。すなわち
Connection conn = DriverManager.getConnection("jdbc:relique:csv:PathToFolderWhereCsvFileIsGoesHere");
これが完全なコードです。
String[] holder = null;
try
{
// load the driver into memory
Class.forName("org.relique.jdbc.csv.CsvDriver");
// create a connection. The first command line parameter is assumed to
// be the directory in which the .csv files are held
Connection conn = DriverManager.getConnection("jdbc:relique:csv:PathToFolderWhereCsvFileIsGoesHere");
// create a Statement object to execute the query with
Statement stmt = conn.createStatement();
// Select the ID and NAME columns from sample.csv
ResultSet results = stmt.executeQuery("SELECT model FROM vehicles where id = 200");
// dump out the results
for(int i=0; i < results.getFetchSize(); i++){
holder[i] = results.getString("model");
}
// clean up
results.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}