public void init() throws Exception { startServer(); setupDataSource(); initTestData(); server = new EmbeddedServer(); H2ExecutionFactory executionFactory = new H2ExecutionFactory(); executionFactory.setSupportsDirectQueryProcedure(true); executionFactory.start(); server.addTranslator("translator-h2", executionFactory); server.start(new EmbeddedConfiguration()); server.deployVDB(new FileInputStream(new File("vdb/h2-debug-vdb.xml"))); conn = server.getDriver().connect("jdbc:teiid:H2VDB", null); // JDBCUtil.executeQuery(conn, "SELECT * FROM PRODUCT ORDER BY ID"); // JDBCUtil.executeUpdate(conn, "INSERT INTO PRODUCT (ID,SYMBOL,COMPANY_NAME) // VALUES(1042,'BA','The Boeing Company')"); JDBCUtil.close(conn); }
protected void prepareInsert() throws SQLException { PreparedStatement pstmt = null; try { pstmt = conn.prepareStatement("INSERT INTO PRODUCT(ID, SYMBOL, COMPANY_NAME) VALUES(?, ?, ?)"); for (int i = 0; i < 1; i++) { pstmt.setInt(1, 101 + i); pstmt.setString(2, "RHA"); pstmt.setString(3, "REDHAT"); pstmt.addBatch(); } pstmt.executeBatch(); if (!conn.getAutoCommit()) { conn.commit(); } } catch (SQLException e) { throw e; } finally { JDBCUtil.close(pstmt); } }