Skip to main content

Posts

Showing posts from August, 2011

Accessing and modifying openoffice base databases from Java

I made a little tool that makes it real easy to access and modify openoffice databases from Java, without having to open oo-base. Here's a code snippet from the unit test: OpenOfficeBaseJPA instance = new OpenOfficeBaseJPA(new File("testdb/TestDatabase.odb")); EntityManager em = instance.createEntityManager(); Integer rowcount = (Integer) em.createNativeQuery( "select count(*) from \"PUBLIC\".\"TestTable\"") .getSingleResult(); em.getTransaction().begin(); em.createNativeQuery( "insert into \"PUBLIC\".\"TestTable\" (\"TestField\") values ('Testvalue')") .executeUpdate(); em.getTransaction().commit(); Integer rowcount2 = (Integer) em.createNativeQuery( "select count(*) from \"PUBLIC\".\"TestTable\"")   .getSingleResult(); assertTrue(rowcount+1==rowcount2); em.close(); instance.saveChanges(); Thread.sl