android mysql 图片路径设置_android SQLite存入图片路径  取出图片并设置到ImageView上...

1.首先获取图片路径

通过getUriFromDrawableRes方法获取​

public Uri getUriFromDrawableRes(Context context, int id) {

Resources resources =

context.getResources();

String path =

ContentResolver.SCHEME_ANDROID_RESOURCE + "://"

+

resources.getResourcePackageName(id) + "/"

+

resources.getResourceTypeName(id) + "/"

+

resources.getResourceEntryName(id);

return (Uri) Uri.parse(path);

}

2.将图片传入数据库

String

[]a={"橙汁","android.resource://com.example.chaxun/drawable/ic_launcher"};​

arg0.execSQL(insertTable, a);

3.取出数据库的路径

SQLiteDatabase sd = null;

​​sd =

cx.getWritableDatabase();//获取一个可写的数据库

​String sel = "select * from chaxun where

name='橙汁'";//准备SQL语句</

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要从MySQL数据库检索数据并将其显示在Android应用程序,您需要使用以下步骤: 1. 创建一个PHP文件来连接MySQL数据库并执行查询操作。 2. 在Android应用程序使用Volley库进行HTTP请求并获取PHP文件返回的JSON数据。 3. 解析JSON数据并将其显示在TextView。 以下是示例代码: 1. 创建PHP文件: ``` <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database_name"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Execute query and get results $sql = "SELECT * FROM table_name"; $result = $conn->query($sql); // Convert results to JSON format $rows = array(); while($r = mysqli_fetch_assoc($result)) { $rows[] = $r; } echo json_encode($rows); // Close connection $conn->close(); ?> ``` 2. 在Android应用程序使用Volley库进行HTTP请求并获取PHP文件返回的JSON数据: ``` // Instantiate the RequestQueue. RequestQueue queue = Volley.newRequestQueue(this); String url = "http://example.com/get_data.php"; // Request a string response from the provided URL. JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url, null, new Response.Listener<JSONArray>() { @Override public void onResponse(JSONArray response) { // Parse JSON data and display in TextView try { JSONObject jsonObject = response.getJSONObject(0); String data = jsonObject.getString("column_name"); textView.setText(data); } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // Handle error } }); // Add the request to the RequestQueue. queue.add(jsonArrayRequest); ``` 3. 解析JSON数据并将其显示在TextView: 在上面的代码示例,我们仅获取了JSON数组的第一个元素并从获取了特定列的值。您可以根据需要解析JSON数据并将其显示在TextView。 希望这可以帮助您开始从MySQL数据库检索数据并将其显示在Android应用程序

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值