gpt4 book ai didi

php - 从Mysql在Sqlite中存储多个数据

转载 作者:行者123 更新时间:2023-11-29 02:58:32 25 4
gpt4 key购买 nike

<分区>

我想将特定用户的数据从mysql 存储到sqlite。我只能接收一行特定用户。

这是我的代码。

登录

JSONObject jsonexercise = userFunction.exerciseItems(name);

try {
System.out.println(" exe try");
if (jsonexercise.getString(KEY_SUCCESS) != null) {
String result = json.getString(KEY_SUCCESS);
System.out.println(" exersise result" + result);
if(Integer.parseInt(result) == 1){
System.out.println("exercise inside parse");
JSONObject json_exercisedata = json.getJSONObject("getexercise");
db.exerciseItem(json_exercisedata.getString(KEY_ENAME),json_exercisedata.getString(KEY_EXERCISE_NAME),json_exercisedata.getString(KEY_DURATION),json_exercisedata.getString(KEY_CALORIE_BURNED),json_exercisedata.getString(KEY_ECREATED_AT));
}
} else {
System.out.println("no exercise item to show");
}
}
catch (JSONException e) {
System.out.println("no exerc item to show");

}

用户函数

public JSONObject exerciseItems(String name){
// Building Parameters

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", get_exetag));

params.add(new BasicNameValuePair("name", name));
System.out.println("in json object name" + name);

// getting JSON Object
JSONObject jsonexercise = jsonParser.getJSONFromUrl(insertURL, params);
// return json
return jsonexercise;
}

数据库处理器

public void exerciseItem(String name, String exercisename,String duration, String calorieburned, String created_at) {
SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();
values.put(KEY_NAME, name); // Name
System.out.println("in db handler insert user the name is" + name);
values.put(KEY_EXERCISENAME, exercisename); // Email
values.put(KEY_DURATION, duration);
values.put(KEY_CALORIE_BURNED, calorieburned);
values.put(KEY_CREATED_AT, created_at); // Created At
// Inserting Row
db.insert(EXERCISE_ITEM, null, values);
db.close(); // Closing database connection
}

php

public function getExeciseitems($name) {
$result = mysql_query("SELECT name,exercisename,duration,calorieburned,created_at FROM exercisedata WHERE name = '$name'") or die(mysql_error());
// check for result
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
$result = mysql_fetch_array($result);
return $result;
} else {
// user not found
return false;
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com