
Signature
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/Java-db-help-ftopict182736.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=615454
I think you are confusing the capabilities of an IDE with those of the
application that the IDE builds. First of all, your program (no JCreator)
will have to serialize the object(s). For this, your classes will have to
implement the Serializable interface. To serialize the object, you can use
something like this:
byte[] data;
try
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream s = new ObjectOutputStream(out);
s.writeObject(project);
s.flush();
s.close();
data = out.toByteArray();
out.close();
}
catch (Exception e) { System.out.println(e); }
Once you have the byte array that represents the "freeze-dried" object, you
can save it in the database as a BLOB. This part can be done using the JDBC.
To get the object back from the database, you will have to repeat the above
process in reverse:
1. Use JDBC to fetch the BLOB from the database and get its binary content
as a byte array. The details will vary from one DB to another; you will need
to consult the database docs on this. Here is an example for MS SQL Server
2000 JDBC driver:
2.
> I am new to programming, but I know how to create classes and other
> minor things. I use JCreator 2.5 LE.
[quoted text clipped - 14 lines]
> Topic URL: http://www.dbForumz.com/Java-db-help-ftopict182736.html
> Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=615454
Alex Molochnikov - 28 Dec 2004 00:25 GMT
Sorry, premature posting...
I think you are confusing the capabilities of an IDE with those of the
application that the IDE builds. First of all, your program (not JCreator)
will have to serialize the object(s). For this, your classes will have to
implement the Serializable interface. To serialize the object, you can use
something like this:
byte[] data;
try
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream s = new ObjectOutputStream(out);
s.writeObject(project);
s.flush();
s.close();
data = out.toByteArray();
out.close();
}
catch (Exception e) { System.out.println(e); }
Once you have the byte array that represents the "freeze-dried" object, you
can save it in the database as a BLOB. This part can be done using the JDBC.
To get the object back from the database, you will have to repeat the above
process in reverse:
1. Use the JDBC to fetch the BLOB from the database and get its binary
content
as a byte array. The details will vary from one DB to another; you will need
to consult the database docs on this. Here is an example for MS SQL Server
2000 JDBC driver:
resultSet = statement.executeQuery(sqlCommand);
try
{
return (rs.getBytes(col));
}
catch (Exception e)
{
System.out.println(e);
return null;
}
2. Deserialize the byte array into an object:
try
{
ByteArrayInputStream in = new ByteArrayInputStream(data);
ObjectInputStream s = new ObjectInputStream(in);
object = s.readObject();
s.close();
in.close();
}
catch (Exception e)
{
System.out.println(e);
}
You should do some reading on JDBC and Java IO to better understand what the
code snippets do.
The IDE has nothing to do with this process.
HTH
Alex Molochnikov
'Gestalt Corporation
www.gestalt.com
> I am new to programming, but I know how to create classes and other
> minor things. I use JCreator 2.5 LE.
[quoted text clipped - 14 lines]
> Topic URL: http://www.dbForumz.com/Java-db-help-ftopict182736.html
> Visit Topic URL to contact author (reg. req'd). Report abuse:
http://www.dbForumz.com/eform.php?p=615454