Code example for PreparedStatement

Methods: close, execute, setInt, setString

0
        PreparedStatement ps = newConx.prepareStatement("INSERT INTO APPLICATION_SHORTCUTS (NAME,"
                        + "DESCRIPTION, APPLICATION, PARENT_RESOURCE_PERMISSION, " 
                        + "DATE_CREATED, DATE_AMENDED) VALUES " + "(?,?,?,?,NOW(),NOW())"); 
        try { 
            upgrader.info("    " + shortName);
            ps.setString(1, shortName);
            ps.setString(2, rs.getString("DESCRIPTION"));
            ps.setString(3, rs.getString("APPLICATION"));
            ps.setInt(4, 0);
            ps.execute();
            PreparedStatement ps2 = newConx.prepareStatement("SELECT RESOURCE_ID FROM APPLICATION_SHORTCUTS WHERE NAME = ?");
            try { 
                ps2.setString(1, shortName);
                ResultSet rs2 = ps2.executeQuery();
                try { 
                    if (rs2.next()) {
                        int oldResourceId = rs.getInt("SHORTCUT_ID");
                        int newResourceId = rs2.getInt("RESOURCE_ID");
                        updateParameters(upgrader, newConx, oldConx, oldResourceId, newResourceId);
                    } else { 
                        throw new Exception("Failed to get new resource Id");
                    } 
                } finally { 
                    rs2.close();
                } 
            } finally { 
                ps2.close();
            } 
        } catch (Exception e) {
            upgrader.warn("Failed to insert application shortcut " + shortName + ". Probably already exists.", e);
        } finally { 
            ps.close();
        } 
    } 
 
    void updateParameters(Upgrader upgrader, Connection newConx, Connection oldConx, int oldResourceId, int newResourceId) throws Exception {
        PreparedStatement ps3 = oldConx.prepareStatement("SELECT * FROM APPLICATION_SHORTCUTS_PARAMETERS WHERE SHORTCUT_ID = ?");