This discussion is archived
3 Replies Latest reply: Apr 11, 2013 11:58 PM by EJP RSS

Serialization Back to Database

995566 Newbie
Currently Being Moderated
Hi Every one, I am facing a little problem here that i cant seem to get past.

I have done Serialization on my Database, i can Read the File into a Text Area. inside my View. I am using MVC in my program. What i am having a problem with is Trying to get this Object that i had Created with Serialization Into my Database as a Backup

My Database Table is made up with the following
ID (Int)
FirstName (text)
LastName (text)
Address (text)
PhoneNumber (int)
bytes (blob)
WRITE_OBJECT_SQL_PATIENT =
                         connection1.prepareStatement("INSERT INTO Patient(Id,FirstName,LastName,Address,PhoneNumber,bytes)" +
                                   "VALUES(?,?,?,?,?,?)");



     public ArrayList<Person> writeJavaObject(ActionEvent evt)
     {
          ArrayList<Person> results = null; // ArrayList <Person> 
          ResultSet resultSet = null; // ResultSet Set to Null

          try 
          {
               // executeQuery returns ResultSet containing matching entries
               resultSet = WRITE_OBJECT_SQL_PATIENT.executeQuery(); //ResultSet equals SelectAllPeople & Execute The Query Above
               results = new ArrayList< Person >(); // Placing Entries into ArrayList

               WRITE_OBJECT_SQL_PATIENT.setString( 1,"Patientid");
               WRITE_OBJECT_SQL_PATIENT.setString( 2, "FirstName" );
               WRITE_OBJECT_SQL_PATIENT.setString( 3, "LastName" );
               WRITE_OBJECT_SQL_PATIENT.setString( 4, "Address" );
               WRITE_OBJECT_SQL_PATIENT.setString( 5, "PhoneNumber" );
               WRITE_OBJECT_SQL_PATIENT.setObject( 6, "object" );

          
          } // end try
          catch ( SQLException sqlException )
          {
               sqlException.printStackTrace();
               close();
          } // end catch
          return results;

     }
This is a Method that is calling the above code but i am getting Can not issue data manipulation statements with executeQuery().
     public static void LOADITEMactionPerformed(ActionEvent evt)
     {
          results - 
                        DBSQLQueries.writeJavaObject(evt);
          
     }
  • 1. Re: Serialization Back to Database
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    I doubt that design will be usable over time. As an example of why - because data model entities are not always mappable in one to one relationships.

    And given that it looks like the connection/statement scope is outside the method it probably isn't thread safe either. And perhaps leaking connections.

    Other than that your question is a bit hard to understand. I can only suppose that when you attempt the write that it fails but you don't specify how. In other words you do not supply the exception and stack trace.

    But as a guess you are not using an updatable query.
  • 2. Re: Serialization Back to Database
    Murray9654 Newbie
    Currently Being Moderated
    Hi
    Statement.executeQuery()
    is only for select quires. you have to use
    Statement.executeUpdate()
    for DML quires.

    Edited by: Muralidhar on Apr 12, 2013 11:52 AM
  • 3. Re: Serialization Back to Database
    EJP Guru
    Currently Being Moderated
    ... and there's not much point in setting prepared-statement parameters after executing it.
    OP wrote:
    Can not issue data manipulation statements with executeQuery()
    jschell wrote:
    Other than that your question is a bit hard to understand. I can only suppose that when you attempt the write that it fails but you don't specify how.
    Missed it completely.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points