View Javadoc
1 /* 2 * CsvJdbc - a JDBC driver for CSV files 3 * Copyright (C) 2001 Jonathan Ackerman 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * You should have received a copy of the GNU Lesser General Public 14 * License along with this library; if not, write to the Free Software 15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 */ 17 package org.relique.jdbc.csv; 18 19 import java.sql.*; 20 import java.util.Properties; 21 import java.io.File; 22 23 /*** 24 * This class implements the Driver interface for the CsvJdbc driver. 25 * 26 * @author Jonathan Ackerman 27 * @author Sander Brienen 28 * @author JD Evora 29 * @author Tomasz Skutnik 30 * @version $Id: CsvDriver.html,v 1.1 2003/05/12 16:19:47 sinisa Exp $ 31 */ 32 33 public class CsvDriver implements Driver 34 { 35 36 public static final String DEFAULT_EXTENSION = ".csv"; 37 public static final char DEFAULT_SEPARATOR = ','; 38 public static final boolean DEFAULT_SUPPRESS = false; 39 public static final String FILE_EXTENSION="fileExtension"; 40 public static final String SEPARATOR="separator"; 41 public static final String SUPPRESS_HEADERS="suppressHeaders"; 42 public static final String CHARSET = "charset"; 43 private final static String URL_PREFIX = "jdbc:relique:csv:"; 44 private Properties info = null; 45 46 47 /*** 48 *Gets the propertyInfo attribute of the CsvDriver object 49 * 50 * @param url Description of Parameter 51 * @param info Description of Parameter 52 * @return The propertyInfo value 53 * @exception SQLException Description of Exception 54 * @since 55 */ 56 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) 57 throws SQLException 58 { 59 return new DriverPropertyInfo[0]; 60 } 61 62 63 /*** 64 *Gets the majorVersion attribute of the CsvDriver object 65 * 66 * @return The majorVersion value 67 * @since 68 */ 69 public int getMajorVersion() 70 { 71 return 1; 72 } 73 74 75 /*** 76 *Gets the minorVersion attribute of the CsvDriver object 77 * 78 * @return The minorVersion value 79 * @since 80 */ 81 public int getMinorVersion() 82 { 83 return 0; 84 } 85 86 87 /*** 88 *Description of the Method 89 * 90 * @param url Description of Parameter 91 * @param info Description of Parameter 92 * @return Description of the Returned Value 93 * @exception SQLException Description of Exception 94 * @since 95 */ 96 public Connection connect(String url, Properties info) throws SQLException 97 { 98 DriverManager.println("CsvJdbc - CsvDriver:connect() - url=" + url); 99 // check for correct url 100 if (!url.startsWith(URL_PREFIX)) 101 { 102 return null; 103 } 104 // get filepath from url 105 String filePath = url.substring(URL_PREFIX.length()); 106 if (!filePath.endsWith(File.separator)) 107 { 108 filePath += File.separator; 109 } 110 111 DriverManager.println("CsvJdbc - CsvDriver:connect() - filePath=" + filePath); 112 113 // check if filepath is a correct path. 114 File checkPath = new File(filePath); 115 if (!checkPath.exists()) 116 { 117 throw new SQLException("Specified path '" + filePath + "' not found !"); 118 } 119 if (!checkPath.isDirectory()) 120 { 121 throw new SQLException( 122 "Specified path '" + filePath + "' is not a directory !"); 123 } 124 125 return new CsvConnection(filePath, info); 126 } 127 128 129 /*** 130 *Description of the Method 131 * 132 * @param url Description of Parameter 133 * @return Description of the Returned Value 134 * @exception SQLException Description of Exception 135 * @since 136 */ 137 public boolean acceptsURL(String url) throws SQLException 138 { 139 DriverManager.println("CsvJdbc - CsvDriver:accept() - url=" + url); 140 return url.startsWith(URL_PREFIX); 141 } 142 143 144 /*** 145 *Description of the Method 146 * 147 * @return Description of the Returned Value 148 * @since 149 */ 150 public boolean jdbcCompliant() 151 { 152 return false; 153 } 154 // This static block inits the driver when the class is loaded by the JVM. 155 static 156 { 157 try 158 { 159 java.sql.DriverManager.registerDriver(new CsvDriver()); 160 } 161 catch (SQLException e) 162 { 163 throw new RuntimeException( 164 "FATAL ERROR: Could not initialise CSV driver ! Message was: " 165 + e.getMessage()); 166 } 167 } 168 } 169

This page automatically generated by Maven