- Forum posts: 1
Mar 3, 2017, 11:55:38 PM via Website
Mar 3, 2017 11:55:38 PM via Website
hello !! i need your help !!
im a Beginner in android studio , i'm trying to get a blob image from mysql data base and to
put it in an imageview but i have to do some convertion ,
here is my code please help me to know where the problem is ,
when i run the emulator it's stop the app while asking to load the pic and put it
i guess the prblm is in the convertion !! help please!!:
public class SearchActivity extends Activity {
ImageView imgview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
imgview= (ImageView)this.findViewById(R.id.imageView);
}
public void getimg() throws android.database.SQLException, ClassNotFoundException{
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn= DriverManager.getConnection ("jdbc:mysql://localhost:3306/appbd","root","");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from imgtable");
Blob b =rs.getBlob(1);
int blobLength = (int) b.length();
byte[] blobAsBytes = b.getBytes(1, blobLength);
Bitmap btm =BitmapFactory.decodeByteArray(blobAsBytes,0,blobAsBytes.length);
imgview.setImageBitmap(btm );
conn.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}