Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / December 2004

Tip: Looking for answers? Try searching our database.

Java db help

Thread view: 
BoraT - 27 Dec 2004 18:55 GMT
I am new to programming, but I know how to create classes and other
minor things. I use JCreator 2.5 LE.
I was wandering on a thing: I want the data i create(object and other
things) to be saved in some files, that when i run the java prog again
I would have an already created objects with the attributes that i
gave them. And when i make changes in the objects(e.g. change the
name) it will be saved too.

So the question is: how to create a database that can be used with
JCreator 2.5 LE?

Thanks in advance!

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

Alex Molochnikov - 28 Dec 2004 00:15 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.