001: /*
002: *
003: * dbfFile/tinySQL JDBC driver
004: *
005: * A lot of this code is based on or directly taken from
006: * George Reese's (borg@imaginary.com) mSQL driver.
007: *
008: * So, it's probably safe to say:
009: *
010: * Portions of this code Copyright (c) 1996 George Reese
011: *
012: * The rest of it:
013: *
014: * Copyright 1996 John Wiley & Sons, Inc.
015: * See the COPYING file for redistribution details.
016: *
017: * $Author: davis $
018: * $Date: 2004/12/18 21:32:10 $
019: * $Revision: 1.1 $
020: *
021: */
022: package com.sqlmagic.tinysql;
023:
024: import java.sql.Connection;
025: import java.sql.DriverPropertyInfo;
026: import java.sql.SQLException;
027: import java.sql.Driver;
028: import java.util.Properties;
029:
030: /**
031: dBase read/write access <br>
032: @author Brian Jepson <bjepson@home.com>
033: @author Marcel Ruff <ruff@swand.lake.de> Added write access to dBase and JDK 2 support
034: */
035: public class dbfFileDriver extends tinySQLDriver {
036:
037: /*
038: *
039: * Instantiate a new dbfFileDriver(), registering it with
040: * the JDBC DriverManager.
041: *
042: */
043: static {
044: try {
045: java.sql.DriverManager.registerDriver(new dbfFileDriver());
046: } catch (Exception e) {
047: e.printStackTrace();
048: }
049: }
050:
051: /**
052: *
053: * Constructs a new dbfFileDriver
054: *
055: */
056: public dbfFileDriver() {
057: super ();
058: }
059:
060: /**
061: *
062: * returns a new dbfFileConnection object, which is cast
063: * to a tinySQLConnection object.
064: *
065: * @exception SQLException when an error occurs
066: * @param user the username - currently unused
067: * @param url the url to the data source
068: * @param d the Driver object.
069: *
070: */
071: public tinySQLConnection getConnection(String user, String url,
072: Driver d) throws SQLException {
073: if (url != (String) null) {
074: if (url.length() > 13)
075: tinySQLGlobals.readLongNames(url.substring(13));
076: }
077: return (tinySQLConnection) new dbfFileConnection(user, url, d);
078: }
079:
080: /**
081: *
082: * Check to see if the URL is a dbfFile URL. It should start
083: * with jdbc:dbfFile in order to qualify.
084: *
085: * @param url The URL of the database.
086: * @return True if this driver can connect to the given URL.
087: *
088: */
089: public boolean acceptsURL(String url) throws SQLException {
090:
091: // make sure the length is at least twelve
092: // before bothering with the substring
093: // comparison.
094: //
095: if (url.length() < 12) {
096: return false;
097: }
098:
099: // if everything after the jdbc: part is
100: // dbfFile, then return true.
101: //
102: return url.substring(5, 12).equals("dbfFile");
103:
104: }
105:
106: }
|