Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Retrieve Image from java database.

package com;
 
import java.io.*;
import java.sql.*;
 
public class DatabaseImageExample {

	public static void main(String args[]){
		try{
			Class.forName("com.mysql.jdbc.Driver");
			Connection con=DriverManager.getConnection("jdbc:mysql://localhost/demo","root","root");
			File file=new File("E:image1.png");
			FileOutputStream fos=new FileOutputStream(file);
			byte b[];
			Blob blob;
			PreparedStatement ps=con.prepareStatement("select * from image_table");
			ResultSet rs=ps.executeQuery();
			while(rs.next()){
			blob=rs.getBlob("image");
			b=blob.getBytes(1,(int)blob.length());
			fos.write(b);
			}
			ps.close();
			fos.close();
			con.close();
			}
       	 catch(Exception e){
			e.printStackTrace();
		}
	}
}
Comment

PREVIOUS NEXT
Code Example
Java :: java window always on top 
Java :: Run the ls command in the terminal to see the uncompiled .java file 
Java :: confirmation dialog android 
Java :: Jax-RS PUT annotation 
Java :: java herencia 
Java :: Janaaa_Sa 
Java :: Java Public Access Modifier package two 
Java :: at org.apache.spark.sql.errors.QueryCompilationErrors$.failedToFindKafkaDataSourceError(QueryCompilationErrors.scala:1037) 
Java :: {1 2 3 4 5 } 
Java :: what is a literal in java 
Java :: api for currency conversion free 
Java :: get value from dynamic input android 
Java :: java loop aray 
Java :: How can i stub Instant object using powermock 
Java :: findbyname in jpa 
Java :: convert object address to string in java 
Java :: how to increase a variable once java 
Java :: Java @SafeVarargs annotation 
Java :: java division int by 0 
Java :: java singleton design pattern 
Java :: rgb code from java color 
Java :: doubly linked list java add an element to the end 
Java :: how to compare two characters in java 
Java :: java find largest number in list 
Java :: multiple return values in function java 
Java :: Java getClass() method 
Java :: java hello world program 
Java :: java get class by string name 
Java :: Java Scanner nextDouble() 
Java :: LocalRegistry java rebind() java8 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =