%@page import="java.sql.*,java.util.*,java.text.*"%> <% response.setHeader("Cache-Control","no-cache"); %> <%! private boolean isSchemaCreated(Connection connection) throws SQLException { // ask the name of all the tables in the database // compare against a list of known tables DatabaseMetaData meta = connection.getMetaData(); ResultSet rs = meta.getTables(null,null,null,new String[] { "TABLE" }); int found = 0; while(rs.next()) { String tableName = rs.getString("TABLE_NAME"); if(tableName.equalsIgnoreCase("resource") || tableName.equalsIgnoreCase("booking")) found++; } rs.close(); return 2 == found; } protected void doUpdates(Connection connection, String[] statements) throws SQLException { Statement stmt = connection.createStatement(); SQLException e = null; try { for(int i = 0;i < statements.length;i++) try { stmt.executeUpdate(statements[i]); } catch(SQLException x) { e = e != null ? e : x; } if(null != e) { throw e; } } finally { stmt.close(); } } private boolean isEmpty(String st) { if(null != st) return st.trim().length() == 0; else return true; } private void doInsertResource(Connection connection, String name, String description) throws SQLException { PreparedStatement stmt = connection.prepareStatement( "insert into resource (name, description) values (?,?)"); try { stmt.setString(1,name); stmt.setString(2,description); stmt.executeUpdate(); } finally { stmt.close(); } } %> <% DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US); Class.forName("org.hsqldb.jdbcDriver"); Connection connection = DriverManager.getConnection("jdbc:hsqldb:db/resourceful", "sa", null); try { connection.setAutoCommit(true); %>
| Name | Description | |
| <%= resources.getString(2) %> | <%= resources.getString(3) %> | |
| booked by <%= bookings.getString(4) %> (<%= dateFormat.format(bookings.getTimestamp(2)) %> - <%= dateFormat.format(bookings.getTimestamp(3)) %>) | ||