android - How to store the arrarylist values into sqlitedb? -


i had stored numbers in phone arraylist need store numbers sqlitedb, can convert them excel sheet easily.

list list = new arraylist();

string number = cur.getstring(cur.getcolumnindex(commondatakinds.phone.number)); list.add(number);

try method store phobne number

public static void storeindb(arraylist longs) throws ioexception, sqlexception {

bytearrayoutputstream bout = new bytearrayoutputstream(); dataoutputstream dout = new dataoutputstream(bout); (long l : longs) {     dout.writelong(l); } dout.close(); byte[] asbytes = bout.tobytearray();  preparedstatement stmt = null;  // this... stmt.setbytes(1, asbytes); stmt.executeupdate(); stmt.close(); 

}

public static arraylist readfromdb() throws ioexception, sqlexception {

arraylist<long> longs = new arraylist<long>(); resultset rs = null;  // this... while (rs.next()) {     byte[] asbytes = rs.getbytes("mylongs");     bytearrayinputstream bin = new bytearrayinputstream(asbytes);     datainputstream din = new datainputstream(bin);     (int = 0; < asbytes.length/8; i++) {         longs.add(din.readlong());     }     return longs; } 

}


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -