Looping a result set for a condition in Java using Jackcess -


using jackcess 2.0.4 trying query table , rows matching particular condition.

map<string, string> testdata = new hashtable<string, string>();  database db = databasebuilder.open(new file("db.mdb")); table table = db.gettable("db_data");  cursor cursor = cursorbuilder.createcursor(table);  while (cursor.findnextrow(collections.singletonmap("case", case))) {     row row = cursor.getcurrentrow();      testdata.put(row.get("key").tostring(), row.get("data").tostring()); } 

the value testdata null no rows returned. not sure missing here.

i have tried below approach. it's still same.

for (row row : cursor.newiterable().addmatchpattern("testcaseid", testcaseid)) {     testdata.put(row.get("key").tostring(), row.get("data").tostring()); } 

check code make sure column names , types match in table. sample data in table named [db_data] ...

rowid  testcaseid  key   data -----  ----------  ----  -----     1           1  key1  data1     2           2  key2  data2     3           1  key3  data3 

... following code ...

map<string, string> testdata = new hashtable<string, string>();  string dbfile = "c:/users/public/test/db.mdb"; try (database db = databasebuilder.open(new file(dbfile))) {     table table = db.gettable("db_data");     cursor cursor = cursorbuilder.createcursor(table);     int testcaseid = 1;     (row row : cursor.newiterable().addmatchpattern("testcaseid", testcaseid)) {         testdata.put(row.get("key").tostring(), row.get("data").tostring());     }      iterator<map.entry<string, string>> = testdata.entryset().iterator();     while (it.hasnext()) {         map.entry<string, string> entry = it.next();         system.out.println(string.format(                 "key: %s, data: %s",                  entry.getkey(),                  entry.getvalue()));     } } catch (exception e) {     e.printstacktrace(system.out); } 

... gives me following console output:

key: key3, data: data3 key: key1, data: data1 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -