|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.h2.tools.Csv
public class Csv
A facility to read from and write to CSV (comma separated values) files. When reading, the BOM (the byte-order-mark) character 0xfeff at the beginning of the file is ignored.
| Constructor Summary | |
|---|---|
Csv()
|
|
| Method Summary | |
|---|---|
void |
close()
INTERNAL |
char |
getEscapeCharacter()
Get the current escape character. |
char |
getFieldDelimiter()
Get the current field delimiter. |
char |
getFieldSeparatorRead()
Get the current field separator for reading. |
java.lang.String |
getFieldSeparatorWrite()
Get the current field separator for writing. |
static Csv |
getInstance()
Deprecated. use the public constructor instead |
char |
getLineCommentCharacter()
Get the line comment character. |
java.lang.String |
getLineSeparator()
Get the current line separator. |
java.lang.String |
getNullString()
Get the current null string. |
boolean |
getPreserveWhitespace()
Whether whitespace in unquoted text is preserved. |
java.lang.String |
getRowSeparatorWrite()
Get the current row separator for writing. |
java.sql.ResultSet |
read(java.io.Reader reader,
java.lang.String[] colNames)
Reads CSV data from a reader and returns a result set. |
java.sql.ResultSet |
read(java.lang.String inputFileName,
java.lang.String[] colNames,
java.lang.String charset)
Reads from the CSV file and returns a result set. |
java.lang.Object[] |
readRow()
INTERNAL |
void |
reset()
INTERNAL |
void |
setEscapeCharacter(char escapeCharacter)
Set the escape character. |
void |
setFieldDelimiter(char fieldDelimiter)
Set the field delimiter. |
void |
setFieldSeparatorRead(char fieldSeparatorRead)
Override the field separator for reading. |
void |
setFieldSeparatorWrite(java.lang.String fieldSeparatorWrite)
Override the field separator for writing. |
void |
setLineCommentCharacter(char lineCommentCharacter)
Set the line comment character. |
void |
setLineSeparator(java.lang.String lineSeparator)
Set the line separator. |
void |
setNullString(java.lang.String nullString)
Set the value that represents NULL. |
java.lang.String |
setOptions(java.lang.String options)
INTERNAL. |
void |
setPreserveWhitespace(boolean value)
Enable or disable preserving whitespace in unquoted text. |
void |
setRowSeparatorWrite(java.lang.String rowSeparatorWrite)
Override the end-of-row marker for writing. |
int |
write(java.sql.Connection conn,
java.lang.String outputFileName,
java.lang.String sql,
java.lang.String charset)
Writes the result set of a query to a file in the CSV format. |
int |
write(java.lang.String outputFileName,
java.sql.ResultSet rs,
java.lang.String charset)
Writes the result set to a file in the CSV format. |
int |
write(java.io.Writer writer,
java.sql.ResultSet rs)
Writes the result set to a file in the CSV format. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Csv()
| Method Detail |
|---|
public static Csv getInstance()
public int write(java.io.Writer writer,
java.sql.ResultSet rs)
throws java.sql.SQLException
writer - the writerrs - the result set
java.sql.SQLException
public int write(java.lang.String outputFileName,
java.sql.ResultSet rs,
java.lang.String charset)
throws java.sql.SQLException
while (rs.next()) {
writeRow(row);
}
outputFileName - the name of the csv filers - the result set - the result set must be positioned before the
first row.charset - the charset or null to use the system default charset
(see system property file.encoding)
java.sql.SQLException
public int write(java.sql.Connection conn,
java.lang.String outputFileName,
java.lang.String sql,
java.lang.String charset)
throws java.sql.SQLException
conn - the connectionoutputFileName - the file namesql - the querycharset - the charset or null to use the system default charset
(see system property file.encoding)
java.sql.SQLException
public java.sql.ResultSet read(java.lang.String inputFileName,
java.lang.String[] colNames,
java.lang.String charset)
throws java.sql.SQLException
inputFileName - the file namecolNames - or null if the column names should be read from the CSV
filecharset - the charset or null to use the system default charset
(see system property file.encoding)
java.sql.SQLException
public java.sql.ResultSet read(java.io.Reader reader,
java.lang.String[] colNames)
throws java.io.IOException
reader - the readercolNames - or null if the column names should be read from the CSV file
java.io.IOException
public java.lang.Object[] readRow()
throws java.sql.SQLException
readRow in interface SimpleRowSourcejava.sql.SQLExceptionpublic void close()
close in interface SimpleRowSource
public void reset()
throws java.sql.SQLException
reset in interface SimpleRowSourcejava.sql.SQLException - if this operation is not supportedpublic void setFieldSeparatorWrite(java.lang.String fieldSeparatorWrite)
fieldSeparatorWrite - the field separatorpublic java.lang.String getFieldSeparatorWrite()
public void setFieldSeparatorRead(char fieldSeparatorRead)
fieldSeparatorRead - the field separatorpublic char getFieldSeparatorRead()
public java.lang.String getRowSeparatorWrite()
public void setRowSeparatorWrite(java.lang.String rowSeparatorWrite)
rowSeparatorWrite - the row separatorpublic void setLineCommentCharacter(char lineCommentCharacter)
lineCommentCharacter - the line comment characterpublic char getLineCommentCharacter()
public void setFieldDelimiter(char fieldDelimiter)
fieldDelimiter - the field delimiterpublic char getFieldDelimiter()
public void setEscapeCharacter(char escapeCharacter)
Data: He said "Hello". Escape character: " Field delimiter: " CSV file: "He said ""Hello""."If the field delimiter is a double quote and the escape character is a backslash, then escaping is done similar to Java (however, only the field delimiter is escaped). Example:
Data: He said "Hello". Escape character: \ Field delimiter: " CSV file: "He said \"Hello\"."The value 0 means no escape character is used.
escapeCharacter - the escape characterpublic char getEscapeCharacter()
public void setLineSeparator(java.lang.String lineSeparator)
lineSeparator - the line separatorpublic java.lang.String getLineSeparator()
public void setNullString(java.lang.String nullString)
nullString - the nullpublic java.lang.String getNullString()
public void setPreserveWhitespace(boolean value)
value - the new value for the settingpublic boolean getPreserveWhitespace()
public java.lang.String setOptions(java.lang.String options)
options - the the options
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||