How can I store Java Objects in JDataStore?

Abstract: How can I store Java Objects in JDataStore?

Here is a sample showing how to create a JDataStore table containing Java Objects. Remeber to add "implements Serializable" to your class definition:

// JavaObject.java

import java.sql.*;
import java.io.*;

class Foo implements Serializable
{
Foo(String s, int i)
{
s1 = s;
i1 = i;
}

public String toString()
{
return "foo: "+s1 + ", " + i1;
}
String s1;
int i1;
};

public class JavaObject
{
public JavaObject()
{
}

static void main(String args[])
{
String DRIVER = "com.borland.datastore.jdbc.DataStoreDriver";
String URL = "jdbc:borland:dslocal:/temp/objectdb.jds";
Connection con= null;
try
{
Class.forName(DRIVER);
con = DriverManager.getConnection(URL, "user", "");
Statement stmt = con.createStatement();

try {
stmt.executeUpdate("drop table ObjectList2;");
}
catch(Exception e)
{};

stmt.executeUpdate("create table ObjectList2 (obj OBJECT);");
PreparedStatement pstmt = con.prepareStatement("insert into ObjectList2 values(?)");

pstmt.setObject(1, new Foo("Moe", 1));
pstmt.executeUpdate();
pstmt.setObject(1, new Integer(2));
pstmt.executeUpdate();
pstmt.setObject(1, new Integer(3));
pstmt.executeUpdate();
pstmt.close();

ResultSet rs = stmt.executeQuery("select * from ObjectList2");
while(rs.next())
{
Object obj = rs.getObject(1);
System.out.println(" "+obj.toString());
}

stmt.close();
}
catch(Exception e)
{
System.out.println(e);
}

try
{
if(con!= null)
con.close();
}
catch(Exception e2)
{
System.out.println(e2.toString());
}
}
}