Hi,

> Apologies if this message is duplicated somewhere. I can't seem to get
> posting to the group to work.

I'm sorry, your message was not posted because new members can't post
until I enable it. The reason for this policy is that there was a lot
of spam recently posted to the list. I was hoping this spam problem
will be solved (by Google) and in fact it got better, but I still like
to keep this policy. Usually I read e-mail at least once a day but
yesterday I could not, so I could not moderate your message.

Does somebody want to co-moderate this list (together with me)? The
'job' is to ban new members that send spam, and allow new members that
don't send spam. On average there is one new member every few days, so
it's not a lot of work. It would reduce the delay for new members to
post on the list. If you are interested, please send a mail to
dbsupport at h2database. com.

Regards,
Thomas


>
> I'm looking at using H2 as a persistent object store. I  am storing/
> retrieving objects objects directly into the row as OTHER type. Works
> well so far, except I ran into this one problem.
>
> I fetch an object by key, then attempt to update a secondary field
> using an updateable result set. The update succeeds BUT my object
> (which was not updated) now comes out of the row as a byte array,
> instead of as a deserialized object. I've tried this with different
> object types (String, Integers, more complex objects) and it seems to
> happen regardless of the object class.
>
> Am I doing something wrong? Is this just a bug?
>
> I'm attaching a simplified example below. Many thanks
>
> --joel carranza
> Gatekeeper Systems
> [EMAIL PROTECTED]
>
> import java.io.*;
> import java.sql.*;
>
> public class UpdateRow {
>
>       static int execute(Connection conn, String sql) throws SQLException {
>               Statement stmt = conn.createStatement();
>               int rv = stmt.executeUpdate(sql);
>               stmt.close();
>               return rv;
>       }
>
>
>       private static Object fetch(Connection conn, String sql) throws
> SQLException {
>               Statement s;
>               ResultSet rs;
>               s = conn.createStatement();
>               rs = s.executeQuery(sql);
>               Object value = null;
>               if(rs.next()) {
>                       value = rs.getObject(1);
>               }
>               rs.close();
>               s.close();
>               return value;
>       }
>
>       public static void main(String[] args) throws SQLException,
> ClassNotFoundException, IOException {
>               Class.forName("org.h2.Driver");
>               File file = File.createTempFile("test", "db");
>               Connection conn =
> DriverManager.getConnection("jdbc:h2:"+file.getAbsolutePath());
>               execute(conn,"CREATE TABLE object_index (id integer primary key,
> object other, number integer)");
>
>               PreparedStatement stmt = conn.prepareStatement("INSERT INTO
> object_index (id,object)  VALUES (1,?)");
>               stmt.setObject(1,"hello", Types.JAVA_OBJECT);
>               stmt.execute();
>
>               // select object (as string) from row
>               System.out.println("select = "+fetch(conn,"SELECT
> object,id,number
> FROM object_index WHERE id =1"));
>               // prints "hello"
>
>               // update row using updatable result set
>               Statement s =
> conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
>               ResultSet rs = s.executeQuery("SELECT object,id,number FROM
> object_index WHERE id =1");
>               if(rs.next()) {
>                       // prints out "hello"
>                       System.out.println("select during update =
> "+rs.getObject(1));
>                       rs.updateInt(2, 1);
>                       rs.updateRow(); // succeeds
>               }
>               rs.close();
>               s.close();
>
>               // select again
>               System.out.println("select after update = "+fetch(conn,"SELECT
> object,id,number FROM object_index WHERE id =1"));
>               // prints byte array
>
>               conn.close();
>       }
>
> }
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to