gpt4 book ai didi

android - 使用 Android 应用程序中的 Json 将多条记录插入 mysql

转载 作者:行者123 更新时间:2023-11-30 00:25:00 25 4
gpt4 key购买 nike

我想使用我的 Android 应用程序中的 Json 在 MySQL 数据库中插入多条记录

如果有人有在 MySQL 中插入多条记录的想法,请告诉我。

谢谢。

这是我的代码:

String TempDial = "";
Cursor cursord = class1.GetDial();
if (cursord.moveToFirst()) {
do {
TempDial = cursord.getString(1);

try{


obj_new.put("UserName", cursord.getString(1));
obj_new.put("Number", cursord.getString(2));
obj_new.put("Time", cursord.getString(3));
json_string = json_string + obj_new.toString() + ",";
} catch (Exception exc) {
}
} while (cursord.moveToNext());
}
if (TempDial.equals("")) {
// Data Not Available
Log.i("Temporary Data", "Not Have Temporary DialCall Data");
} else {
// Get Some Data
json_string = json_string.substring(0, json_string.length()-1);
json_string += "]}";
Log.i("Json String", json_string);
Log.i("Temporary Data", "Temporary DialCall Data Available");

try{


HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
HttpConnectionParams.setSoTimeout(httpParams, 5000);
HttpClient client = new DefaultHttpClient(httpParams);

String url = "http://api.spy.theplanetit.com/Insert_Local_Missed_Call.php";

HttpPost request = new HttpPost(url);
request.setEntity(new ByteArrayEntity(json_string.getBytes("UTF8")));
request.setHeader("json", json_string);
HttpResponse response = client.execute(request);

Log.i("Data Report", response.getStatusLine().toString());
} catch (Exception exc) {
}

//class1.DeleteDial(); }

最佳答案

客户端:网址应该是这样的

http://api.spy.theplanetit.com/Insert_Local_Missed_Call.php?EMP_ID=your_value&EMP_PWD=your_value

服务器端:

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
@Path("/path_name")
public Service postService(@FormParam("EMP_ID") String param1,@FormParam("EMP_PWD") String param2)
{

Service ud=new Service();
String retrievedbatch="";
String uname="",retrievedpass="";
try
{
connectionQuerry();

PreparedStatement statement = con.prepareStatement("inser into table_name values('"+param1+"','"+param2+"'");
ResultSet result = statement.executeQuery();
System.out.println("DataBase table accessed");


con.close();
}

catch(Exception e)
{
e.printStackTrace();
ud.setStatus("Failed");
System.out.println(e.getMessage().toString());
}

return ud;
}

关于android - 使用 Android 应用程序中的 Json 将多条记录插入 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22953716/

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