Re: using BLOB objects and ...
- From: "Matt Humphrey" <matth@xxxxxxxxxxxxxx>
- Date: Mon, 3 Jul 2006 16:38:02 -0400
"Rhino" <no.offline.contact.please@xxxxxxxxxx> wrote in message
news:e8bogm$1ee$1@xxxxxxxxxxxxxxxx
"vijjus4u" <vijjus4u@xxxxxxxxx> wrote in message
news:1151947558.239128.310900@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
you can insert any kind of file to database by using following codeYour code seems to be assuming that the original poster is storing a
i hope this program will usefull for you
Example on storing images into BLOB data type.
- Managing SQL 92 data types (BLOB, CLOB and Ref)
BLOB (Binary Large OBject)
Used to store binary informations like images, audio files etc
-For each byte one byte of memory will be allocated
-Size can vary up to 4GB for each entry
CLOB (Character LOB)
-Used to store character information like plain, word documents
-For each character two bytes of memory is allocated
-Size up to 4GB
Ref (Reference):
-The column declared with this data type instead of storing a file into
DB contains
a pointer pointing to the file located in the hard disk
-Size up to 4GB
*/
// ImageStore.java
import java.sql.*;
import java.io.*;
public class ImageStore
{
public static void main(String rags[]) thro
ws Exception
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:mysqlDSN","root",
"active");
PreparedStatement pstmt=con.prepareStatement("insert into temp
values(?,?)");
File f=new File("xml-pic.jpg");
FileInputStream fis=new FileInputStream(f);
pstmt.setInt(1, 1);
pstmt.setBinaryStream(2, fis, (int)f.length());
int i=pstmt.executeUpdate();
System.out.println(i+" record inserted");
pstmt.close();
con.close();
}// main()
}// class
single JPEG. But he is actually storing a 4 dimensional array containing
thousands of booleans. I'm not sure your code will work for an Object of
the kind the poster wants to store.../
Actually, this code simply copies an arbitrary byte stream (which happens to
come from a jpb) into a BLOB parameter of a prepared statement. The OP can
apply this by serializing the original 4-dimensional array to a byte stream,
something along the lines of this:
Object object = ? // arbitrary serializable object
ByteArrayOutputStream bos = new ByteArrayOutputStream ();
ObjectOutputStream oos = new ObjectOutputStream (bos);
oos.writeObject (object); oos.flush ();
bos.close ();
byte [] byteArray = bos.toByteArray ();
pstmt.setBytes (2, byteArray);
Cheers,
Matt Humphrey matth@xxxxxxxxxxxxxx http://www.iviz.com/
.
- Follow-Ups:
- Re: using BLOB objects and ...
- From: Rhino
- Re: using BLOB objects and ...
- References:
- using BLOB objects and ...
- From: ali
- Re: using BLOB objects and ...
- From: vijjus4u
- Re: using BLOB objects and ...
- From: Rhino
- using BLOB objects and ...
- Prev by Date: Re: new to Java - best resource?
- Next by Date: Anyone use JBuilder Foundation with J2ME?
- Previous by thread: Re: using BLOB objects and ...
- Next by thread: Re: using BLOB objects and ...
- Index(es):
Relevant Pages
|