我在mysql workbunch中創建了一個數據庫,並將類似blob的圖片存儲在它中。
現在我想在我的應用程序使用該圖片,如何從mysql glob類型獲取圖像
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數據。 –
當然,如果你[包括正確的權限](https://stackoverflow.com/a/18843518/783412) – hd1
נשמהשלאבאדבראיתיכפרה –