Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Java db help

 
   Database Forums (Home) -> Java RSS
Next:  error 14151  
Author Message
BoraT




Joined: Dec 27, 2004
Posts: 2



(Msg. 1) Posted: Mon Dec 27, 2004 1:43 pm
Post subject: Java db help

I am new around here, so I don't know if this topic belongs here.

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!

 >> Stay informed about: Java db help 
Back to top
Login to vote
Alex Molochnikov1

External


Since: Jan 25, 2004
Posts: 41



(Msg. 2) Posted: Mon Dec 27, 2004 8:40 pm
Post subject: Re: Java db help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.

"BoraT" wrote in message

 > 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!
 >
 > --
 > <a rel="nofollow" style='text-decoration: none;' href="http://www.dbForumz.com/" target="_blank">http://www.dbForumz.com/</a> This article was posted by author's request
 > Articles individually checked for conformance to usenet standards
<font color=purple> > Topic URL: <a rel="nofollow" style='text-decoration: none;' href="http://www.dbForumz.com/Java-db-help-ftopict182736.html</font" target="_blank">http://www.dbForumz.com/Java-db-help-ftopict182736.html</font</a>>
 > Visit Topic URL to contact author (reg. req'd). Report abuse:
<a rel="nofollow" style='text-decoration: none;' href="http://www.dbForumz.com/eform.php?p=615454" target="_blank">http://www.dbForumz.com/eform.php?p=615454</a>

 >> Stay informed about: Java db help 
Back to top
Login to vote
Alex Molochnikov1

External


Since: Jan 25, 2004
Posts: 41



(Msg. 3) Posted: Mon Dec 27, 2004 8:40 pm
Post subject: Re: Java db help [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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
<a rel="nofollow" style='text-decoration: none;' href="http://www.gestalt.com" target="_blank">www.gestalt.com</a>

"BoraT" wrote in message

 > 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!
 >
 > --
 > <a rel="nofollow" style='text-decoration: none;' href="http://www.dbForumz.com/" target="_blank">http://www.dbForumz.com/</a> This article was posted by author's request
 > Articles individually checked for conformance to usenet standards
<font color=purple> > Topic URL: <a rel="nofollow" style='text-decoration: none;' href="http://www.dbForumz.com/Java-db-help-ftopict182736.html</font" target="_blank">http://www.dbForumz.com/Java-db-help-ftopict182736.html</font</a>>
 > Visit Topic URL to contact author (reg. req'd). Report abuse:
<a rel="nofollow" style='text-decoration: none;' href="http://www.dbForumz.com/eform.php?p=615454" target="_blank">http://www.dbForumz.com/eform.php?p=615454</a>
 >> Stay informed about: Java db help 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
java - Hello Im working with jdbc on a MSSQL Database. In my java client im executing a stored procedure called myProc on the database. Im doing this with the following code: ...... Statement stmt = con.createStatement(); String sql1 ="execute myProc&quo...

java or c# please help - I am starting a new application, it needs to use db such as access or msde. I know I can do this easily in c# or Java but my question is can I distribute a package as easy if it is created with java and say derby db as I can with windows based. It....

java - Do any of you know someone experienced in Java that is interested in a full time job in Tucson, Omaha or Dallas? Company dies not pay relo but has an excellent reputation as a great place to work. If you are interested sheck out www.retaliz.com

Java and Microsoft SQL - Hi ! I am experiencing some problems with MSSQL (ver 8.0). While I can execute sub-select statement directly on a MSSQL server, I cannot do the same thing in JDBC. Like the following statement( JDBC throws exception about mismatched type) select..

Snr. Java Developer - Snr. Java Developer Front endOur Client is the leading provider of online customized remarketing solutions for the automotive industry. Their entire business is focused on providing dealers and institutional sellers with the specialized expertise..
   Database Forums (Home) -> Java All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]