Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7645579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:58:35+00:00 2026-05-31T09:58:35+00:00

I am using following code: Note that i HAVE TO SEND SQL Query so

  • 0

I am using following code: Note that i HAVE TO SEND SQL Query so using this procedure.

currentReceipt.image is a 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 shows a value of [B@43eb4218 or similar to that.

Now this data is saved in database. Please tell me is the image is correctly saving in database and can i retrieve it? If not then any preferable way , do tell me.

Best Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:58:36+00:00Added an answer on May 31, 2026 at 9:58 am

    Storing an image in SQLite is not a good idea. You should save the image on SD card and store its path in database.

    Anyhow, if you still want to store the image in database, then you need to do the following:

    1. Convert image into bytes
    2. Convert bytes into Base64 encoded string
    3. Save the Base64 encoded string into database

    *Reversing the process will give the image.

    Another solution is to convert your column smallThumb type to BLOB and store the bytes directly. But for this you need to modify your table.


    In your code, change the method imageToDB as below:

    public String imageToDB (byte[] image){
        return Base64.encodeToString(image, Base64.DEFAULT).trim();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code. Note that I am not using a using as
I am trying to create a user using code. I have the following that
I have the following code that saves a map into shared memory using boost
I'm using following code but cannot return data from MySQL. This is the output:
Using the following code I get a nice formatted string: Request.QueryString.ToString Gives me something
I am using following code to combine .mp4 and .caf into .mov . (Note
This following code snippet works fine using jQuery1.2.3, but it doesn’t work with latest
If I have the following code: var value : String = StringUtil.substitute(The value {0}
I am using the following code, upload.php, to try to have someone upload a
First, some visualization of the code. I have the following images that are dynamically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.