Re: Serializing PreparedStatement, or: how do create a database history?



> I first thought about serializing the PreparedStatement, but first of
> all it is not serializable, second, all status about the database is lost.
> Simply saving the SQL string does not help, as there can be binary
> objects in the query which are set using the PerparedStatement.
> As this is an extension to an existing program, and PreparedStatement is
> used there all over, building something around the PreparedStatement
> seems like the only solution.

PreparedStatement is an interface... so assuming the existing program was
written correctly (by declaring its variables using the interface type, and
not any concrete type), you could create a new class which wraps any
PreparedStatement (the one you get from your JDBC driver) into a new, more
functional PreparedStatement containing your new "database not available
transparency layer".

I'm no database expert, but are you 110% sure that adding such a "lets defer
our interactions to this database" layer makes sense? As with many
apparently clever ideas, it may actually not make any sense after closer
inspection. I don't know. I'll leave this question to others to ask/answer.


.



Relevant Pages

  • Re: get SQL statement from PreparedStatement
    ... PreparedStatement to the database to execute? ... SQL into some driver or database specific format that allows for value ...
    (comp.lang.java.programmer)
  • Re: Serializing PreparedStatement, or: how do create a database history?
    ... If the db is not available, all updates/inserts and deletes must be saved and later be executed on the database (SQL select is not needed). ... I first thought about serializing the PreparedStatement, but first of all it is not serializable, second, all status about the database is lost. ... As this is an extension to an existing program, and PreparedStatement is used there all over, building something around the PreparedStatement seems like the only solution. ...
    (comp.lang.java.databases)
  • Re: Serializing PreparedStatement, or: how do create a database history?
    ... If the db is not available, all updates/inserts and deletes must be saved and later be executed on the database (SQL select is not needed). ... I first thought about serializing the PreparedStatement, but first of all it is not serializable, second, all status about the database is lost. ... As this is an extension to an existing program, and PreparedStatement is used there all over, building something around the PreparedStatement seems like the only solution. ...
    (comp.lang.java.databases)
  • Re: get SQL statement from PreparedStatement
    ... That isn't how prepared statements work. ... The idea behind the prepared statement is that the driver or database will precompile the SQL into some driver or database specific format that allows for value bindings. ... If what you really wanted to achieve was to known what parameters are being passed to the PreparedStatement there are JDBC spy tools that can help. ...
    (comp.lang.java.programmer)
  • Re: get SQL statement from PreparedStatement
    ... PreparedStatement to the database to execute? ... SQL into some driver or database specific format that allows for value ... Typically the execution plan for the SQL is determined by this ...
    (comp.lang.java.programmer)