KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sqlmagic > tinysql > dbfFileDriver


1 /*
2  *
3  * dbfFile/tinySQL JDBC driver
4  *
5  * A lot of this code is based on or directly taken from
6  * George Reese's (borg@imaginary.com) mSQL driver.
7  *
8  * So, it's probably safe to say:
9  *
10  * Portions of this code Copyright (c) 1996 George Reese
11  *
12  * The rest of it:
13  *
14  * Copyright 1996 John Wiley & Sons, Inc.
15  * See the COPYING file for redistribution details.
16  *
17  * $Author: davis $
18  * $Date: 2004/12/18 21:32:10 $
19  * $Revision: 1.1 $
20  *
21  */

22 package com.sqlmagic.tinysql;
23
24 import java.sql.Connection JavaDoc;
25 import java.sql.DriverPropertyInfo JavaDoc;
26 import java.sql.SQLException JavaDoc;
27 import java.sql.Driver JavaDoc;
28 import java.util.Properties JavaDoc;
29
30
31 /**
32 dBase read/write access <br>
33 @author Brian Jepson <bjepson@home.com>
34 @author Marcel Ruff <ruff@swand.lake.de> Added write access to dBase and JDK 2 support
35 */

36 public class dbfFileDriver extends tinySQLDriver {
37
38   /*
39    *
40    * Instantiate a new dbfFileDriver(), registering it with
41    * the JDBC DriverManager.
42    *
43    */

44   static {
45     try {
46       java.sql.DriverManager.registerDriver(new dbfFileDriver());
47     } catch (Exception JavaDoc e) {
48       e.printStackTrace();
49     }
50   }
51
52   /**
53    *
54    * Constructs a new dbfFileDriver
55    *
56    */

57   public dbfFileDriver() {
58     super();
59   }
60
61   /**
62    *
63    * returns a new dbfFileConnection object, which is cast
64    * to a tinySQLConnection object.
65    *
66    * @exception SQLException when an error occurs
67    * @param user the username - currently unused
68    * @param url the url to the data source
69    * @param d the Driver object.
70    *
71    */

72   public tinySQLConnection getConnection
73                  (String JavaDoc user, String JavaDoc url, Driver JavaDoc d)
74                   throws SQLException JavaDoc {
75
76     return (tinySQLConnection) new dbfFileConnection(user, url, d);
77   }
78
79   /**
80    *
81    * Check to see if the URL is a dbfFile URL. It should start
82    * with jdbc:dbfFile in order to qualify.
83    *
84    * @param url The URL of the database.
85    * @return True if this driver can connect to the given URL.
86    *
87    */

88   public boolean acceptsURL(String JavaDoc url) throws SQLException JavaDoc {
89
90     // make sure the length is at least twelve
91
// before bothering with the substring
92
// comparison.
93
//
94
if( url.length() < 12 ) {
95       return false;
96     }
97
98     // if everything after the jdbc: part is
99
// dbfFile, then return true.
100
//
101
return url.substring(5,12).equals("dbfFile");
102
103   }
104
105 }
106
Popular Tags