how to save an object to MYSQL database as a blob.....

I'm trying to store an object getting from a particular url to the database(MySQL) as a blob

Step i'm following is like this...

> I'm getting the object from the url which can be a pdf, image....

> I'm converting that in to the array of bytes....

> array of bytes are then converted to blob & putting into the database...

> in my database the datatype is blob.

I don't whether i'm following write method........

I'm just copying the code i'm using & the error i'm getting just below this

So if any body can help me in this i'll be so thankful.....

import java.net.*;

import java.io.*;

import java.sql.*;

import java.sql.Blob;

import java.io.OutputStream;

public class URLConndb implements java.io.Serializable {

public static void main(String[] args) {

// TODO code application logic here

try{

URL yahoo = new URL("http://172.16.15.100/amc");

//URL yahoo = new URL("http://google.co.in");

Object o = null;

Connection con = null;

Statement stmt = null;

ResultSet rs = null;

java.sql.PreparedStatement pstmt;

URLConnection yc = yahoo.openConnection();

System.out.println("Perfect upto this.....");

o = yc.getContent();

Blob b= null;

////////////////

ByteArrayOutputStream bos = new ByteArrayOutputStream() ;

ObjectOutputStream out;

out = new ObjectOutputStream(bos) ;

out.writeObject(o);

out.close();// Get the bytes of the serialized object

byte[] buf = bos.toByteArray();

int len = b.setBytes(1,buf);

///////////////////////////////

if(b!= null)

{

System.out.println("object present");

System.out.println("Content type : "+yc.getContentType());

try{

System.out.println("insert try..");

Class.forName("com.mysql.jdbc.Driver").newInstance();

System.out.println("Driver Registered") ;

con = DriverManager.getConnection ("jdbc:mysql://localhost/gapi","root","adhina");

System.out.println("Connection Established........") ;

stmt = con.createStatement();

rs =stmt.executeQuery("select * from objdatabase");

int id=0;

//Inserting values into the database.

try{

System.out.println("insert try........");

pstmt=con.prepareStatement("insert into srchurl values(?)") ;

pstmt.setBlob(1,b);

pstmt.executeUpdate() ;

System.out.println("Udated ........");

}

catch(Exception e)

{

System.out.println("Excepiton : "+e);

}

}

catch(Exception e)

{

System.out.println("Excepiton : "+e);

}

}

else

System.out.println("not present");

}

catch(Exception e)

{

System.out.println("Excepiton : "+e);

}

}

}

Error i'm getting during runtime

Excepiton : java.io.NotSerializableException: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream

Could anybody help me

[3106 byte] By [surya_sujia] at [2007-10-3 1:04:59]
# 1
I see, someone failed to follow the advice given here: http://forum.java.sun.com/thread.jspa?threadID=754265
CeciNEstPasUnProgrammeura at 2007-7-14 18:01:26 > top of Java-index,Java Essentials,Java Programming...
# 2
NotSerializableExceptionThis should be pretty obivous, though. You serialize something that's not serializable. Why didn't you just read the API? And thanks to you not printing the stack traces and always catching "Exception", there's no easy way to see where it happens.
CeciNEstPasUnProgrammeura at 2007-7-14 18:01:26 > top of Java-index,Java Essentials,Java Programming...