/** * Read a table and write it into a shape file. * @param connection Active connection * @param fileName Shape file name or URI * @param tableReference Table name or select query * Note : The select query must be enclosed in parenthesis * @param encoding File encoding * @throws IOException * @throws SQLException */ public static void exportTable(Connection connection, String fileName, String tableReference, String encoding) throws IOException, SQLException { String regex = ".*(?i)\\b(select|from)\\b.*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(tableReference); SHPDriverFunction shpDriverFunction = new SHPDriverFunction(); if (matcher.find()) { if (tableReference.startsWith("(") && tableReference.endsWith(")")) { shpDriverFunction.exportResultset(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding); } else { throw new SQLException("The select query must be enclosed in parenthesis: '(SELECT * FROM ORDERS)'."); } } else { shpDriverFunction.exportTable(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding); } }
/** * Read a table and write it into a shape file. * @param connection Active connection * @param fileName Shape file name or URI * @param tableReference Table name or select query * Note : The select query must be enclosed in parenthesis * @param encoding File encoding * @throws IOException * @throws SQLException */ public static void exportTable(Connection connection, String fileName, String tableReference, String encoding) throws IOException, SQLException { String regex = ".*(?i)\\b(select|from)\\b.*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(tableReference); SHPDriverFunction shpDriverFunction = new SHPDriverFunction(); if (matcher.find()) { if (tableReference.startsWith("(") && tableReference.endsWith(")")) { shpDriverFunction.exportResultset(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding); } else { throw new SQLException("The select query must be enclosed in parenthesis: '(SELECT * FROM ORDERS)'."); } } else { shpDriverFunction.exportTable(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding); } }