⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csvstatement.java

📁 一种解析csv文件特别好的方法
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

    /**
     *Gets the resultSetConcurrency attribute of the CsvStatement object
     *
     * @return                   The resultSetConcurrency value
     * @exception  SQLException  Description of Exception
     * @since
     */
    public int getResultSetConcurrency() throws SQLException
    {
        throw new SQLException("Not Supported !");
    }


    /**
     *Gets the resultSetType attribute of the CsvStatement object
     *
     * @return                   The resultSetType value
     * @exception  SQLException  Description of Exception
     * @since
     */
    public int getResultSetType() throws SQLException
    {
        return this.isScrollable;
    }


    /**
     *Gets the connection attribute of the CsvStatement object
     *
     * @return                   The connection value
     * @exception  SQLException  Description of Exception
     * @since
     */
    public Connection getConnection() throws SQLException
    {
        return connection;
    }


    /**
     *Description of the Method
     *
     * @param  sql               Description of Parameter
     * @return                   Description of the Returned Value
     * @exception  SQLException  Description of Exception
     * @since
     */
    public ResultSet executeQuery(String sql) throws SQLException
    {
        DriverManager.println("CsvJdbc - CsvStatement:executeQuery() - sql= " + sql);
        SqlParser parser = new SqlParser();
        try
            {
                parser.parse(sql);
            }
        catch (Exception e)
            {
                throw new SQLException("Syntax Error. " + e.getMessage());
            }

			  DriverManager.println("Connection Path: " + connection.getPath());
			  DriverManager.println("Parser Table Name: " + parser.getTableName()); 
			  DriverManager.println("Connection Extension: " + connection.getExtension());
        
        String fileName = connection.getPath() + parser.getTableName() + connection.getExtension();
        
			  DriverManager.println("CSV file name: " + fileName);
        
        File checkFile = new File(fileName);

        if (!checkFile.exists())
            {
                throw new SQLException("Cannot open data file '" + fileName + "'  !");
            }

        if (!checkFile.canRead())
            {
                throw new SQLException("Data file '" + fileName + "'  not readable !");
            }

        CSVReaderAdapter reader;
        try
            {
                if (isScrollable == ResultSet.TYPE_SCROLL_SENSITIVE){
                  reader = new CSVScrollableReader(fileName, connection.getSeperator(),
                                       connection.isSuppressHeaders(), connection.getCharset());
                } else {
                  reader = new CsvReader(fileName, connection.getSeperator(),
                                       connection.isSuppressHeaders(), connection.getCharset());
                }
            }
        catch (Exception e)
            {
                throw new SQLException("Error reading data file. Message was: " + e);
            }

        CsvResultSet resultSet = new CsvResultSet(this,reader,
                                                  parser.getTableName(), parser.getColumnNames(), this.isScrollable,parser.getWhereColumn(), parser.getWhereValue());
        resultSets.add(resultSet);

        return resultSet;
    }


    /**
     *Description of the Method
     *
     * @param  sql               Description of Parameter
     * @return                   Description of the Returned Value
     * @exception  SQLException  Description of Exception
     * @since
     */
    public int executeUpdate(String sql) throws SQLException
    {
        throw new SQLException("Not Supported !");
    }


    /**
     * Releases this <code>Statement</code> object's database
     * and JDBC resources immediately instead of waiting for
     * this to happen when it is automatically closed.
     * It is generally good practice to release resources as soon as
     * you are finished with them to avoid tying up database
     * resources.
     * <P>
     * Calling the method <code>close</code> on a <code>Statement</code>
     * object that is already closed has no effect.
     * <P>
     * <B>Note:</B> A <code>Statement</code> object is automatically closed
     * when it is garbage collected. When a <code>Statement</code> object is
     * closed, its current <code>ResultSet</code> object, if one exists, is
     * also closed.
     *
     * @exception SQLException if a database access error occurs
     */
    public void close() throws SQLException {
        // close all result sets
        for(Enumeration i = resultSets.elements(); i.hasMoreElements(); ) {
            CsvResultSet resultSet = (CsvResultSet)i.nextElement();
            resultSet.close();
        }
    }


    /**
     *Description of the Method
     *
     * @exception  SQLException  Description of Exception
     * @since
     */
    public void cancel() throws SQLException
    {
        throw new SQLException("Not Supported !");
    }


    /**
     *Description of the Method
     *
     * @exception  SQLException  Description of Exception
     * @since
     */
    public void clearWarnings() throws SQLException
    {
        throw new SQLException("Not Supported !");
    }


    /**
     *Description of the Method
     *
     * @param  p0                Description of Parameter
     * @return                   Description of the Returned Value
     * @exception  SQLException  Description of Exception
     * @since
     */
    public boolean execute(String p0) throws SQLException
    {
        throw new SQLException("Not Supported !");
    }


    /**
     *Adds a feature to the Batch attribute of the CsvStatement object
     *
     * @param  p0                The feature to be added to the Batch attribute
     * @exception  SQLException  Description of Exception
     * @since
     */
    public void addBatch(String p0) throws SQLException
    {
        throw new SQLException("Not Supported !");
    }


    /**
     *Description of the Method
     *
     * @exception  SQLException  Description of Exception
     * @since
     */
    public void clearBatch() throws SQLException
    {
        throw new SQLException("Not Supported !");
    }


    /**
     *Description of the Method
     *
     * @return                   Description of the Returned Value
     * @exception  SQLException  Description of Exception
     * @since
     */
    public int[] executeBatch() throws SQLException
    {
        throw new SQLException("Not Supported !");
    }

    //---------------------------------------------------------------------
    // JDBC 3.0
    //---------------------------------------------------------------------

    public boolean getMoreResults(int current) throws SQLException {
        throw new UnsupportedOperationException("Statement.getMoreResults(int) unsupported");
    }

    public ResultSet getGeneratedKeys() throws SQLException {
        throw new UnsupportedOperationException("Statement.getGeneratedKeys() unsupported");
    }

    public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
        throw new UnsupportedOperationException("Statement.executeUpdate(String,int) unsupported");
    }

    public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
        throw new UnsupportedOperationException("Statement.executeUpdate(String,int[]) unsupported");
    }

    public int executeUpdate(String sql, String[] columnNames) throws SQLException {
        throw new UnsupportedOperationException("Statement.executeUpdate(String,String[]) unsupported");
    }

    public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
        throw new UnsupportedOperationException("Statement.execute(String,int) unsupported");
    }

    public boolean execute(String sql, int[] columnIndexes) throws SQLException {
        throw new UnsupportedOperationException("Statement.execute(String,int[]) unsupported");
    }

    public boolean execute(String sql, String[] columnNames) throws SQLException {
        throw new UnsupportedOperationException("Statement.execute(String,String[]) unsupported");
    }

    public int getResultSetHoldability() throws SQLException {
        throw new UnsupportedOperationException("Statement.getResultSetHoldability() unsupported");
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -