【发布时间】:2018-01-25 11:52:15
【问题描述】:
我在 mysql workbunch 中创建了一个数据库,并将图片作为 blob 类型存储在其中。
现在我想在我的应用中使用这张图片,
Class.forName("com.mysql.jdbc.Driver");
try(Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sys", "root", "Elior204")){
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT img FROM Sentences where id=1");
ImageView image = (ImageView) findViewById(R.id.imageView1);
Blob b =rs.getBlob(1);
int blobLength = (int) b.length();
byte[] blobAsBytes = b.getBytes(1, blobLength);
Bitmap btm =BitmapFactory.decodeByteArray(blobAsBytes,0,blobAsBytes.length);
image.setImageBitmap(btm );
con.close();
问题是,我该如何继续?
【问题讨论】:
-
你不能在Android中直接访问mysql。你需要一个web服务来访问mysql数据。
-
当然可以,如果你include the right permissions
-
נשמה של אבא דבר איתי כפרה
-
jdbc:mysql://localhost永远不会在 Android 设备中工作...除非你真的在那里运行 mysql 服务器