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
Post a Comment