Visualize image from SQL database

I’m using android studio to create an app. The idea is to load a image … Read more Visualize image from SQL database

I’m using android studio to create an app. The idea is to load a image from a SQL database. But I’m having difficulties with it. I’m able to load the text parts which are in the database, but I’m unable to visualize the image. I also want to visualize the text and picture with the same button click.
The datatypes of my database are

ID = int

Name = char(10)

Filepath = char(150)

Picture = image

Down here you see my
I’ve tried many ways already to visualize it already, but can’t seem to find it working. I’ve also changed the getByte to getBlob but this doesn’t make a difference.

package com.allcodingtutorials.sqlconnection;


import android.os.Bundle;
import android.os.Environment;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class MainActivity extends AppCompatActivity {

    EditText Rnumber;
    Button update;
    TextView name, path;
    ImageView picture;

    Connection connection;

    protected void onCreate(Bundle savedInstanceState) {
        Rnumber = findViewById(;
        update  = (Button) findViewById(;
        name  = findViewById(;
        path = findViewById(;
        picture = findViewById(;

        update.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                String loadData = Rnumber.getText().toString();
                ConSQL con = new ConSQL();
                connection = con.conclass();
                if(con !=null){
                    try {
                        String sqlstatement="Select * From DatabasePictures where ID='"+ loadData +"'";
                        Statement smt = connection.createStatement();
                        ResultSet set = smt.executeQuery(sqlstatement);
                        while ({

                        //    byte[] image = set.getByte(4);
                        //    Bitmap bitmap = BitmapFactory.decodeByteArray(image,0, image.length);
                        //   picture.setImageBitmap(bitmap);

                    catch (Exception e)

Does anyone have some advice or tips how to solve this.

Source: JavaSript – Stack Overflow

Leave a Reply

Your email address will not be published. Required fields are marked *