Best viewed in 1024 X 800 resolution... Leave a comment if u like an article...
Google
 
Web tezcols.blogspot.com

Wednesday, September 06, 2006

Insert an image into database...

/**
* @author Tez K N V
*/
import java.sql.*;
import java.io.*;
public class Gifi {
public Gifi(){

try{
File f=new File("bell.gif");
//Name of the image is bell.gif
InputStream is=new FileInputStream(f);
byte buff[]=new byte[is.available()];
int re=is.read(buff);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mydsn","scott","tiger");
PreparedStatement pstmt=con.prepareStatement("insert into gifo values(?,?)");
//I am using oracle database and my gifo table has int and blob columns
pstmt.setInt(1,3);
pstmt.setBytes(2,buff);
pstmt.execute();
}catch(Exception e){
System.out.println(e);e.printStackTrace();
}
}

public static void main(String s[]){
new Gifi();
}
}


Try to retrieve an image from database... I will post abt tht in another article...

tezcols

Labels:

0 Comments:

Post a Comment

<< Home