Hi, Dear all:
I felt confused with usage of data type: "OTHER" in h2, it is  
announced " a byte array is used", and "Serialization and  
deserialization is done on the client side only.". So how should it  
looks like?

Here is my scenario:
--- --- ---
[1] I created the table, and use myobject to save the serialized java  
object.
"create table testtable (id VARCHAR(50), myobject OTHER);";

[2] insert the data by PreparedStatement:
"insert into testtable values(?, ?);";

ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(myobject);
oos.flush();
byte[] byteArray = bos.toByteArray();

pstmt.setString(1, "idxxx");
pstmt.setObject(2, byteArray);


[3] query the data from database
"select myobject from testtable where id = ?;";

this.pstat.setString(1, "idxxx");
ResultSet rs = this.pstat.executeQuery();
                        
rs.next();
byte[] byteArray = (byte[]) rs.getObject("myobject");

ObjectInputStream oip = new ObjectInputStream(new  
ByteArrayInputStream(byteArray));
MyObject myobject = (MyObject) oip.readObject();

--- --- ---

Is the aforementioned code snippet correct?

However, i was always prompted when arrived "byte[] byteArray =  
(byte[]) rs.getObject("myobject");":

   org.h2.jdbc.JdbcSQLException: No data is available [2000-107]
        at org.h2.message.Message.getSQLException(Message.java:103)
        at org.h2.message.Message.getSQLException(Message.java:114)
        at org.h2.message.Message.getSQLException(Message.java:77)
        at org.h2.message.Message.getSQLException(Message.java:149)
        at org.h2.jdbc.JdbcResultSet.checkOnValidRow(JdbcResultSet.java:2993)
        at org.h2.jdbc.JdbcResultSet.get(JdbcResultSet.java:2999)
        at org.h2.jdbc.JdbcResultSet.get(JdbcResultSet.java:3016)
        at org.h2.jdbc.JdbcResultSet.getObject(JdbcResultSet.java:480)
        at  
ch.eif.gridgroup.magate.km.MatchMaker.queryMatchJob(MatchMaker.java: 
1126)
        at  
ch 
.eif 
.gridgroup.magate.km.MatchMaker.useFCFS_BatchProcess(MatchMaker.java: 
504)
        at ch.eif.gridgroup.magate.km.MatchMaker.scheduleJobs(MatchMaker.java: 
373)
        at  
ch 
.eif.gridgroup.magate.km.MatchMaker.localjobSubmitted(MatchMaker.java: 
1064)
        at ch.eif.gridgroup.magate.km.MatchMaker.jobSubmitted(MatchMaker.java: 
350)
        at  
ch.eif.gridgroup.magate.km.ModuleController.body(ModuleController.java: 
120)
        at eduni.simjava.Sim_entity.run(Sim_entity.java:603)

Thanks a lot!

Regards
ye






--~--~---------~--~----~------------~-------~--~----~
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