我正在使用以下代碼:請注意,我必須使用此過程發送SQL查詢。正在保存使用sql查詢方法的圖像
currentReceipt.image
是byte[]
String updateQuery = "INSERT INTO MAReceipts(userId, transactionId, transactionType, receiptIndex, referenceNo, image, smallThumb, comments, createdOn, updatedOn) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
java.util.Date today = new java.util.Date();
long t = today.getTime();
java.sql.Date now = new java.sql.Date(t);
for(int i = 0; i < receipts.size(); i++)
{
try{
Receipt currentReceipt = receipts.get(i);
String[] valVars = {
stringToDB(transaction.userId),
integerToDB(transaction.transactionId),
integerToDB(transaction.transactionType.getValue()),
integerToDB(i),
stringToDB(currentReceipt.referenceNo),
(currentReceipt.image != null ? imageToDB(currentReceipt.image): "null"),
(currentReceipt.smallThumb != null ? imageToDB(currentReceipt.smallThumb): "null"), // NEED TO CHANGE THIS TO SMALL THUMB
stringToDB(currentReceipt.comments),
dateToDB(now),
dateToDB(now)
};
mDb.execSQL(updateQuery, valVars);
}catch (Exception e){
Log.e("Error in transaction", e.toString());
return false;
}
}
public String imageToDB (byte[] image)
{
String convertedImage = image.toString();
return convertedImage;
}
return convertedImage
示出的[[email protected]
的值或相似。
現在這些數據保存在數據庫中。請告訴我圖像正確保存在數據庫中,我可以檢索它嗎?如果沒有,那麼請告訴我。
問候
我怎樣才能找回它回來? – 2012-03-16 09:29:20
簡單地通過從數據庫中獲取Base64字符串,然後'byte [] image = Base64.decode(「Base64StringfromDatabase」,Base64.DEFAULT);' – waqaslam 2012-03-16 09:32:43
btw,它不讀什麼Base64 – 2012-03-16 09:32:49