Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* CsvJdbc - a JDBC driver for CSV files
* Copyright (C) 2001 Jonathan Ackerman
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.relique.jdbc.csv;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.net.URLDecoder;
import java.sql.Connection;
import java.sql.Date;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Logger;
import org.relique.io.TableReader;
/**
* This class implements the java.sql.Driver JDBC interface for the CsvJdbc driver.
*/
public class CsvDriver implements Driver
{
public static final String DEFAULT_EXTENSION = ".csv";
public static final String DEFAULT_SEPARATOR = ",";
public static final char DEFAULT_QUOTECHAR = '"';
public static final String DEFAULT_HEADERLINE = null;
public static final boolean DEFAULT_SUPPRESS = false;
public static final boolean DEFAULT_IS_HEADER_FIXED_WIDTH = true;
public static final boolean DEFAULT_TRIM_HEADERS = true;
public static final boolean DEFAULT_TRIM_VALUES = false;
public static final String DEFAULT_COLUMN_TYPES = "String";
public static final boolean DEFAULT_INDEXED_FILES = false;
public static final String DEFAULT_TIMESTAMP_FORMAT = null;
public static final String DEFAULT_DATE_FORMAT = "YYYY-MM-DD";
public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";
public static final boolean DEFAULT_USE_DATE_TIME_FORMATTER = false;
public static final String DEFAULT_COMMENT_CHAR = null;
public static final String DEFAULT_SKIP_LEADING_LINES = null;
public static final String DEFAULT_MAX_DATA_LINES = "0";
public static final String DEFAULT_IGNORE_UNPARSEABLE_LINES = "False";
public static final String DEFAULT_MISSING_VALUE = null;
public static final String DEFAULT_FILE_TAIL_PREPEND = "False";
public static final String DEFAULT_DEFECTIVE_HEADERS = "False";
public static final String DEFAULT_SKIP_LEADING_DATA_LINES = "0";
public static final String FILE_EXTENSION = "fileExtension";
public static final String SEPARATOR = "separator";
public static final String QUOTECHAR = "quotechar";
public static final String HEADERLINE = "headerline";
public static final String SUPPRESS_HEADERS = "suppressHeaders";
public static final String IS_HEADER_FIXED_WIDTH = "isHeaderFixedWidth";
public static final String TRIM_HEADERS = "trimHeaders";
public static final String TRIM_VALUES = "trimValues";
public static final String COLUMN_TYPES = "columnTypes";
public static final String INDEXED_FILES = "indexedFiles";
public static final String TIMESTAMP_FORMAT = "timestampFormat";
public static final String DATE_FORMAT = "dateFormat";
public static final String TIME_FORMAT = "timeFormat";
public static final String LOCALE = "locale";
public static final String USE_DATE_TIME_FORMATTER = "useDateTimeFormatter";
public static final String COMMENT_CHAR = "commentChar";
public static final String SKIP_LEADING_LINES = "skipLeadingLines";
public static final String MAX_DATA_LINES = "maxDataLines";
public static final String IGNORE_UNPARSEABLE_LINES = "ignoreNonParseableLines";
public static final String MISSING_VALUE = "missingValue";
public static final String FILE_TAIL_PREPEND = "fileTailPrepend";
public static final String DEFECTIVE_HEADERS = "defectiveHeaders";
public static final String SKIP_LEADING_DATA_LINES = "skipLeadingDataLines";
public static final String TRANSPOSED_LINES = "transposedLines";
public static final String TRANSPOSED_FIELDS_TO_SKIP = "transposedFieldsToSkip";
public static final String CHARSET = "charset";
public final static String URL_PREFIX = "jdbc:relique:csv:";
public static final String CRYPTO_FILTER_CLASS_NAME = "cryptoFilterClassName";
public static final String TIME_ZONE_NAME = "timeZoneName";
public static final String DEFAULT_TIME_ZONE_NAME = "UTC";
// choosing Rome makes sure we change chronology from Julian to Gregorian on
// 1582-10-04/15, as SQL does.
public static final String QUOTE_STYLE = "quoteStyle";
public static final String DEFAULT_QUOTE_STYLE = "SQL";
public static final String READER_CLASS_PREFIX = "class:";
public static final String ZIP_FILE_PREFIX = "zip:";
public static final String CLASSPATH_PREFIX = "classpath:";
public static final String FIXED_WIDTHS = "fixedWidths";
public static final String FUNCTION = "function";
public static final String RANDOM_SEED = "randomSeed";
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
throws SQLException
{
return new DriverPropertyInfo[0];
}
@Override
public int getMajorVersion()
{
return 1;
}
@Override
public int getMinorVersion()
{
return 0;
}
@Override
public Connection connect(String url, Properties info) throws SQLException
{
writeLog("CsvDriver:connect() - url=" + url);
// check for correct url
if (!url.startsWith(URL_PREFIX))
{
return null;
}
Enumeration