Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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();
- java.sql.Blob blob = rs.getBlob(1);
- byte[] imageContents = blob.getBytes(1, new Integer(blob.length()).intValue());
- image = (ImageView) findViewById(R.id.imageView1);
- button = (Button) findViewById(R.id.btnChangeImage);
- button.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- java.io.File tmpFileForImage = java.io.File.createTemporaryFile("image", ".png"); // or whatever your extension happens to be
- java.io.BufferedOutputStream bos = new java.io.BufferedOutputStream(new java.io.FileOutputStream(tmpFileForImage);
- bos.write(imageContents);
- bos.close();
- image.setImageResource(tmpFileForImage.getAbsolutePath());
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement