/** * Writes the result set of a query to a file in the CSV format. * * @param conn the connection * @param outputFileName the file name * @param sql the query * @param charset the charset or null to use the system default charset * (see system property file.encoding) * @return the number of rows written */ public int write(Connection conn, String outputFileName, String sql, String charset) throws SQLException { Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery(sql); int rows = write(outputFileName, rs, charset); stat.close(); return rows; }
int rows = csv.write(conn, v0.getString(), v1.getString(), charset); result = ValueInt.get(rows);
/** * Writes the result set of a query to a file in the CSV format. * * @param conn the connection * @param outputFileName the file name * @param sql the query * @param charset the charset or null to use the system default charset * (see system property file.encoding) * @return the number of rows written */ public int write(Connection conn, String outputFileName, String sql, String charset) throws SQLException { Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery(sql); int rows = write(outputFileName, rs, charset); stat.close(); return rows; }
/** * Writes the result set of a query to a file in the CSV format. * * @param conn the connection * @param outputFileName the file name * @param sql the query * @param charset the charset or null to use the system default charset * (see system property file.encoding) * @return the number of rows written */ public int write(Connection conn, String outputFileName, String sql, String charset) throws SQLException { Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery(sql); int rows = write(outputFileName, rs, charset); stat.close(); return rows; }
/** * Writes the result set of a query to a file in the CSV format. * * @param conn * the connection * @param fileName * the file name * @param sql * the query * @param charset * the charset or null to use UTF-8 * @return the number of rows written * @throws SQLException */ public int write(Connection conn, String fileName, String sql, String charset) throws SQLException { Statement stat = conn.createStatement(); ResultSet rs = stat.executeQuery(sql); int rows = write(fileName, rs, charset); stat.close(); return rows; }
/** * Export a resultset to a TSV file * * @param connection * @param res * @param fileName * @param progress * @param encoding * @throws java.sql.SQLException */ public void exportFromResultSet(Connection connection, ResultSet res, File fileName, ProgressVisitor progress, String encoding) throws SQLException { Csv csv = new Csv(); String csvOptions = "charset=UTF-8 fieldSeparator=\t fieldDelimiter=\t"; if (encoding != null) { csvOptions = String.format("charset=%s fieldSeparator=\t fieldDelimiter=\t", encoding); } csv.setOptions(csvOptions); csv.write(fileName.getPath(), res, null); }
@Override public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress) throws SQLException, IOException { if(FileUtil.isExtensionWellFormated(fileName, "csv")){ final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); TableLocation location = TableLocation.parse(tableReference, isH2); Statement st = null; try { st = connection.createStatement(); new Csv().write(fileName.getPath(), st.executeQuery("SELECT * FROM " + location.toString()), null); } finally { if (st != null) { st.close(); } } } else{ throw new SQLException("Only .csv extension is supported"); } }
@Override public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress) throws SQLException, IOException { if (FileUtil.isExtensionWellFormated(fileName, "tsv")) { final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); TableLocation location = TableLocation.parse(tableReference, isH2); Statement st = null; try { st = connection.createStatement(); Csv csv = new Csv(); csv.setFieldDelimiter('\t'); csv.setFieldSeparatorWrite("\t"); csv.write(fileName.getPath(), st.executeQuery("SELECT * FROM " + location.toString()), null); } finally { if (st != null) { st.close(); } } } else { throw new SQLException("Only .tsv extension is supported"); } }
@Override public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress) throws SQLException, IOException { if (FileUtil.isExtensionWellFormated(fileName, "tsv")) { final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); TableLocation location = TableLocation.parse(tableReference, isH2); Statement st = null; try { st = connection.createStatement(); Csv csv = new Csv(); csv.setFieldDelimiter('\t'); csv.setFieldSeparatorWrite("\t"); csv.write(fileName.getPath(), st.executeQuery("SELECT * FROM " + location.toString()), null); } finally { if (st != null) { st.close(); } } } else { throw new SQLException("Only .tsv extension is supported"); } }
@Override public void exportTable(Connection connection, String tableReference, File fileName, ProgressVisitor progress) throws SQLException, IOException { if (FileUtil.isExtensionWellFormated(fileName, "tsv")) { final boolean isH2 = JDBCUtilities.isH2DataBase(connection.getMetaData()); TableLocation location = TableLocation.parse(tableReference, isH2); Statement st = null; try { st = connection.createStatement(); Csv csv = new Csv(); csv.setFieldDelimiter('\t'); csv.setFieldSeparatorWrite("\t"); csv.write(fileName.getPath(), st.executeQuery("SELECT * FROM " + location.toString()), null); } finally { if (st != null) { st.close(); } } } else { throw new SQLException("Only .tsv extension is supported"); } }
csv.setOptions(csvOptions); csv.write(fileName.getPath(), st.executeQuery("SELECT * FROM " + location.toString()), null); } finally { if (st != null) {
csv.setOptions(csvOptions); csv.write(fileName.getPath(), st.executeQuery("SELECT * FROM " + location.toString()), null); } finally { if (st != null) {
int rows = csv.write(conn, v0.getString(), v1.getString(), charset); result = ValueInt.get(rows);
int rows = csv.write(conn, v0.getString(), v1.getString(), charset); result = ValueInt.get(rows);
csv.setLineSeparator(lineSeparator); int rows = csv.write(conn, v0.getString(), v1.getString(), charset); result = ValueInt.get(rows); break;