public class Csv extends Object implements SimpleRowSource
| 构造器和说明 |
|---|
Csv() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close()
INTERNAL
|
boolean |
getCaseSensitiveColumnNames()
Get the current case sensitive column names setting.
|
char |
getEscapeCharacter()
Get the current escape character.
|
char |
getFieldDelimiter()
Get the current field delimiter.
|
char |
getFieldSeparatorRead()
Get the current field separator for reading.
|
String |
getFieldSeparatorWrite()
Get the current field separator for writing.
|
char |
getLineCommentCharacter()
Get the line comment character.
|
String |
getLineSeparator()
Get the line separator used for writing.
|
String |
getNullString()
Get the current null string.
|
boolean |
getPreserveWhitespace()
Whether whitespace in unquoted text is preserved.
|
boolean |
getWriteColumnHeader()
Whether the column header is written.
|
ResultSet |
read(Reader reader,
String[] colNames)
Reads CSV data from a reader and returns a result set.
|
ResultSet |
read(String inputFileName,
String[] colNames,
String charset)
Reads from the CSV file and returns a result set.
|
Object[] |
readRow()
INTERNAL
|
void |
reset()
INTERNAL
|
void |
setCaseSensitiveColumnNames(boolean caseSensitiveColumnNames)
Override the case sensitive column names setting.
|
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(String fieldSeparatorWrite)
Override the field separator for writing.
|
void |
setLineCommentCharacter(char lineCommentCharacter)
Set the line comment character.
|
void |
setLineSeparator(String lineSeparator)
Set the line separator used for writing.
|
void |
setNullString(String nullString)
Set the value that represents NULL.
|
String |
setOptions(String options)
INTERNAL.
|
void |
setPreserveWhitespace(boolean value)
Enable or disable preserving whitespace in unquoted text.
|
void |
setWriteColumnHeader(boolean value)
Enable or disable writing the column header.
|
int |
write(Connection conn,
String outputFileName,
String sql,
String charset)
Writes the result set of a query to a file in the CSV format.
|
int |
write(String outputFileName,
ResultSet rs,
String charset)
Writes the result set to a file in the CSV format.
|
int |
write(Writer writer,
ResultSet rs)
Writes the result set to a file in the CSV format.
|
public int write(Writer writer, ResultSet rs) throws SQLException
writer - the writerrs - the result setSQLException - on failurepublic int write(String outputFileName, ResultSet rs, String charset) throws 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 charsetSQLException - on failurepublic int write(Connection conn, String outputFileName, String sql, String charset) throws SQLException
conn - the connectionoutputFileName - the file namesql - the querycharset - the charset or null to use the system default charset
(see system property file.encoding)SQLException - on failurepublic ResultSet read(String inputFileName, String[] colNames, String charset) throws 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 charsetSQLException - on failurepublic ResultSet read(Reader reader, String[] colNames) throws IOException
reader - the readercolNames - or null if the column names should be read from the CSV
fileIOException - on failurepublic Object[] readRow() throws SQLException
readRow 在接口中 SimpleRowSourceSQLException - on failurepublic void close()
close 在接口中 SimpleRowSourcepublic void reset()
throws SQLException
reset 在接口中 SimpleRowSourceSQLException - if this operation is not supportedpublic void setFieldSeparatorWrite(String fieldSeparatorWrite)
fieldSeparatorWrite - the field separatorpublic String getFieldSeparatorWrite()
public void setCaseSensitiveColumnNames(boolean caseSensitiveColumnNames)
caseSensitiveColumnNames - whether column names are case sensitivepublic boolean getCaseSensitiveColumnNames()
public void setFieldSeparatorRead(char fieldSeparatorRead)
fieldSeparatorRead - the field separatorpublic char getFieldSeparatorRead()
public 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(String lineSeparator)
lineSeparator - the line separatorpublic String getLineSeparator()
public void setNullString(String nullString)
nullString - the nullpublic String getNullString()
public void setPreserveWhitespace(boolean value)
value - the new value for the settingpublic boolean getPreserveWhitespace()
public void setWriteColumnHeader(boolean value)
value - the new value for the settingpublic boolean getWriteColumnHeader()
Copyright © 2022. All rights reserved.