Posts

Showing posts with the label database

store and retrieve image data to any database in java

We will insert image data into database in byte[] format Here is a piece of code to convert image data into byte[]:  // image file File file = new File("images/extjsfirstlook.jpg");  // create byte with specified size byte[] bFile = new byte[(int) file.length()]; try {  FileInputStream fileInputStream = new FileInputStream(file);   // bFile is initialized fileInputStream.read(bFile); fileInputStream.close(); } catch (Exception e) { e.printStackTrace(); } //now you can store bFile in database       Here is a piece of code to convert byte[] data into image: try {     // create output stream with a file path where you want to store  // your image on your drive FileOutputStream fos = FileOutputStream("images/output.jpg"); // it will write data byte data into the file specified fos.write(book.getImage()); fos.close() } catch (Exception e) { e.printStackTrace(); } ...