Để chèn 7 giá trị trong một cột, bạn có thể sử dụng dấu phẩy phân cách như thế này
nơi Total_Score_P1 là một mảng chuỗi
// chuỗi mảng
String[] Total_Score = new String[] { p1e1,p1e2,p1e3,p1e4,p1e5,p1e6 };
// Convderting it into a single string
String result_ScoreP1 = ("" + Arrays.asList(Total_Score_P1)).
replaceAll("(^.|.$)", " ").replace(", ", " , ");
result_ScoreP1 sẽ
// đầu ra của số này
result_ScoreP1 = "p1e1,p1e2,p1e3,p1e4,p1e5,p1e6";
chèn nó như là một chuỗi duy nhất trong cơ sở dữ liệu và khi lấy nó trong một lần nữa phá vỡ ở các bộ phận như
// một chuỗi array list
// truy vấn bị sa thải
public ArrayList<String> rulTable(String id) {
// TODO Auto-generated method stub
ArrayList<String> Ruleob = new ArrayList<String>();
Cursor c_rule;
try
{
c_rule = db.query(NameTable, new String[]{
columns1
},
Rule_COurseID + "=" + id ,
null, null,
null, null, null);
c_rule.moveToFirst();
// if there is data available after the cursor's pointer, add
// it to the ArrayList that will be returned by the method.
if (!c_rule.isAfterLast())
{
do
{
Ruleob.add(c_rule.getString(0));
}
while (c_rule.moveToNext());
}
// let java know that you are through with the cursor.
c_rule.close();
}
catch(Exception e)
{
}
return Ruleob;
}
//list to get elements
ArrayList<String> ListOne = new ArrayList<String>();
ArrayList<String> row ;
try{
// received values
row = db.TheTable(id);
String r1 = row .get(0);
}
catch(Exception e)
{
}
StringTokenizer st2 = new StringTokenizer(r1, "||");
while(st2.hasMoreTokens()) {
String Desc = st2.nextToken();
System.out.println(Desc+ "\t");
ListOne.add(Desc);
//
}
Nguồn
2012-05-21 12:20:58
nếu bạn muốn lưu trữ mảng trong một cột, sau đó đặt giá trị tất cả ngày của bạn vào mảng json và lưu nó vào trong cơ sở dữ liệu. –