📄 csvconnection.java
字号:
/*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.relique.jdbc.csv;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Savepoint;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;
/**
* This class implements the Connection interface for the CsvJdbc driver.
*
* @author Jonathan Ackerman
* @author Sander Brienen
* @author Michael Maraya
* @author Tomasz Skutnik
* @version $Id: CsvConnection.java,v 1.12 2004/08/09 05:03:05 jackerm Exp $
*/
public class CsvConnection implements Connection {
/** Directory where the CSV files to use are located */
private String path;
/** File extension to use */
private String extension = CsvDriver.DEFAULT_EXTENSION;
/** Field separator to use */
private char separator = CsvDriver.DEFAULT_SEPARATOR;
/** Should headers be suppressed */
private boolean suppressHeaders = CsvDriver.DEFAULT_SUPPRESS;
/** Collection of all created Statements */
private Vector statements = new Vector();
/** Charset that should be used to read the files */
private String charset = null;
/** Stores whether this Connection is closed or not */
private boolean closed;
/**
* Creates a new CsvConnection that takes the supplied path
* @param path directory where the CSV files are located
*/
protected CsvConnection(String path) {
// validate argument(s)
if(path == null || path.length() == 0) {
throw new IllegalArgumentException(
"'path' argument may not be empty or null");
}
this.path = path;
}
/**
* Creates a new CsvConnection that takes the supplied path and properties
* @param path directory where the CSV files are located
* @param info set of properties containing custom options
*/
protected CsvConnection(String path, Properties info) {
this(path);
// check for properties
if(info != null) {
// set the file extension to be used
if(info.getProperty(CsvDriver.FILE_EXTENSION) != null) {
extension = info.getProperty(CsvDriver.FILE_EXTENSION);
}
// set the separator character to be used
if(info.getProperty(CsvDriver.SEPARATOR) != null) {
separator = info.getProperty(CsvDriver.SEPARATOR).charAt(0);
}
// set the header suppression flag
if(info.getProperty(CsvDriver.SUPPRESS_HEADERS) != null) {
suppressHeaders = Boolean.valueOf(info.getProperty(
CsvDriver.SUPPRESS_HEADERS)).booleanValue();
}
// default charset
if (info.getProperty(CsvDriver.CHARSET) != null) {
charset = info.getProperty(CsvDriver.CHARSET);
}
}
}
/**
* Creates a <code>Statement</code> object for sending
* SQL statements to the database.
* SQL statements without parameters are normally
* executed using <code>Statement</code> objects. If the same SQL statement
* is executed many times, it may be more efficient to use a
* <code>PreparedStatement</code> object.
* <P>
* Result sets created using the returned <code>Statement</code>
* object will by default be type <code>TYPE_FORWARD_ONLY</code>
* and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
*
* @return a new default <code>Statement</code> object
* @exception SQLException if a database access error occurs
*/
public Statement createStatement() throws SQLException {
CsvStatement statement = new CsvStatement(this, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE);
statements.add(statement);
return statement;
}
/**
* Creates a <code>PreparedStatement</code> object for sending
* parameterized SQL statements to the database.
* <P>
* A SQL statement with or without IN parameters can be
* pre-compiled and stored in a <code>PreparedStatement</code> object. This
* object can then be used to efficiently execute this statement
* multiple times.
*
* <P><B>Note:</B> This method is optimized for handling
* parametric SQL statements that benefit from precompilation. If
* the driver supports precompilation,
* the method <code>prepareStatement</code> will send
* the statement to the database for precompilation. Some drivers
* may not support precompilation. In this case, the statement may
* not be sent to the database until the <code>PreparedStatement</code>
* object is executed. This has no direct effect on users; however, it does
* affect which methods throw certain <code>SQLException</code> objects.
* <P>
* Result sets created using the returned <code>PreparedStatement</code>
* object will by default be type <code>TYPE_FORWARD_ONLY</code>
* and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
*
* @param sql an SQL statement that may contain one or more '?' IN
* parameter placeholders
* @return a new default <code>PreparedStatement</code> object containing the
* pre-compiled SQL statement
* @exception SQLException if a database access error occurs
*/
public PreparedStatement prepareStatement(String sql) throws SQLException {
throw new UnsupportedOperationException(
"Connection.prepareStatement(String) unsupported");
}
/**
* Creates a <code>CallableStatement</code> object for calling
* database stored procedures.
* The <code>CallableStatement</code> object provides
* methods for setting up its IN and OUT parameters, and
* methods for executing the call to a stored procedure.
*
* <P><B>Note:</B> This method is optimized for handling stored
* procedure call statements. Some drivers may send the call
* statement to the database when the method <code>prepareCall</code>
* is done; others
* may wait until the <code>CallableStatement</code> object
* is executed. This has no
* direct effect on users; however, it does affect which method
* throws certain SQLExceptions.
* <P>
* Result sets created using the returned <code>CallableStatement</code>
* object will by default be type <code>TYPE_FORWARD_ONLY</code>
* and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
*
* @param sql an SQL statement that may contain one or more '?'
* parameter placeholders. Typically this statement is a JDBC
* function call escape string.
* @return a new default <code>CallableStatement</code> object containing the
* pre-compiled SQL statement
* @exception SQLException if a database access error occurs
*/
public CallableStatement prepareCall(String sql) throws SQLException {
throw new UnsupportedOperationException(
"Connection.prepareCall(String) unsupported");
}
/**
* Converts the given SQL statement into the system's native SQL grammar.
* A driver may convert the JDBC SQL grammar into its system's
* native SQL grammar prior to sending it. This method returns the
* native form of the statement that the driver would have sent.
*
* @param sql an SQL statement that may contain one or more '?'
* parameter placeholders
* @return the native form of this statement
* @exception SQLException if a database access error occurs
*/
public String nativeSQL(String sql) throws SQLException {
throw new UnsupportedOperationException(
"Connection.nativeSQL(String) unsupported");
}
/**
* Sets this connection's auto-commit mode to the given state.
* If a connection is in auto-commit mode, then all its SQL
* statements will be executed and committed as individual
* transactions. Otherwise, its SQL statements are grouped into
* transactions that are terminated by a call to either
* the method <code>commit</code> or the method <code>rollback</code>.
* By default, new connections are in auto-commit
* mode.
* <P>
* The commit occurs when the statement completes or the next
* execute occurs, whichever comes first. In the case of
* statements returning a <code>ResultSet</code> object,
* the statement completes when the last row of the
* <code>ResultSet</code> object has been retrieved or the
* <code>ResultSet</code> object has been closed. In advanced cases, a
* single statement may return multiple results as well as output
* parameter values. In these cases, the commit occurs when all results and
* output parameter values have been retrieved.
* <P>
* <B>NOTE:</B> If this method is called during a transaction, the
* transaction is committed.
*
* @param autoCommit <code>true</code> to enable auto-commit mode;
* <code>false</code> to disable it
* @exception SQLException if a database access error occurs
* @see #getAutoCommit
*/
public void setAutoCommit(boolean autoCommit) throws SQLException {
throw new UnsupportedOperationException(
"Connection.setAutoCommit(boolean) unsupported");
}
/**
* Retrieves the current auto-commit mode for this <code>Connection</code>
* object.
*
* @return the current state of this <code>Connection</code> object's
* auto-commit mode
* @exception SQLException if a database access error occurs
* @see #setAutoCommit
*/
public boolean getAutoCommit() throws SQLException {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -