Re: Java db help

From: Alex Molochnikov (NOBODY_at_NOSPAM.COM)
Date: 12/28/04

  • Next message: natG: "HSQLDB and Jonas clarification please."
    Date: Tue, 28 Dec 2004 00:25:05 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

    "BoraT" <UseLinkToEmail@dbForumz.com> wrote in message
    news:41d05aaf$1_4@alt.athenanews.com...
    > 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!
    >
    > --
    > 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


  • Next message: natG: "HSQLDB and Jonas clarification please."

    Relevant Pages

    • Re: Java db help
      ... I think you are confusing the capabilities of an IDE with those of the ... First of all, your program (no JCreator) ... This part can be done using the JDBC. ... To get the object back from the database, you will have to repeat the above ...
      (comp.lang.java.databases)
    • How to check if byte array is compressed or not?
      ... I have some data stored in the database as blob. ... into byte array using jdbc. ... Now I need to read the byte array using ...
      (comp.lang.java.programmer)
    • How to Find out if java byte array is compressed
      ... I have some data stored in the database as blob. ... into byte array using jdbc. ... Now I need to read the byte array using ...
      (comp.lang.java.help)
    • Re: How to check if byte array is compressed or not?
      ... >> I have some data stored in the database as blob. ... >> into byte array using jdbc. ... Now I need to read the byte array using ... The problem is I want to know if the data in the database ...
      (comp.lang.java.programmer)
    • Re: Mixing P/R philosophy with OO (within J2EE).
      ... I have observed the work of literally hundreds of Java developers. ... Treating a database like a mere "persistence storage mechanisms" is on ... JDBC - Never before in history were so many database API's ... Topmind, if you're reading this, isn't this a good example of OOP? ...
      (comp.object)