KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > smallsql > database > SSDriver


1 /* =============================================================
2  * SmallSQL : a free Java DBMS library for the Java(tm) platform
3  * =============================================================
4  *
5  * (C) Copyright 2004-2006, by Volker Berlin.
6  *
7  * Project Info: http://www.smallsql.de/
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ---------------
28  * SSDriver.java
29  * ---------------
30  * Author: Volker Berlin
31  *
32  */

33 package smallsql.database;
34
35 import java.io.StringBufferInputStream JavaDoc;
36 import java.sql.*;
37 import java.util.Properties JavaDoc;
38
39 public class SSDriver implements Driver {
40
41     static final String JavaDoc URL_PREFIX = "jdbc:smallsql";
42     
43     static SSDriver drv;
44     static {
45         try{
46             drv = new SSDriver();
47             java.sql.DriverManager.registerDriver(drv);
48 //DriverManager.setLogStream(System.out);
49
//DriverManager.setLogStream(new java.io.PrintStream(new java.io.FileOutputStream("jdbc.log")));
50
}catch(Throwable JavaDoc e){
51             e.printStackTrace();
52         }
53     }
54     
55
56     public Connection connect(String JavaDoc url, Properties JavaDoc info) throws SQLException {
57         Properties JavaDoc props = (Properties JavaDoc)info.clone();
58         if(!acceptsURL(url)) return null;
59         int idx1 = url.indexOf( ':', 5); // search after "jdbc:"
60
if(idx1 > 0){
61             int idx2 = url.indexOf('?', idx1+1);
62             String JavaDoc dbPath = (idx2 > 0) ? url.substring(idx1+1, idx2) : url.substring(idx1+1);
63             props.setProperty("dbpath", dbPath);
64             if(idx2 > 0){
65                 String JavaDoc propsString = url.substring(idx2+1);
66                 propsString = propsString.replace(';', '\n');
67                 try {
68                     Properties JavaDoc urlProps = new Properties JavaDoc(props);
69                     urlProps.load(new StringBufferInputStream JavaDoc(propsString));
70                     props = urlProps;
71                 } catch (Exception JavaDoc e) {
72                     e.printStackTrace();
73                 }
74             }
75         }
76         return new SSConnection( props );
77     }
78     
79     
80     public boolean acceptsURL(String JavaDoc url){
81         return url.startsWith(URL_PREFIX);
82     }
83     
84     
85     public DriverPropertyInfo[] getPropertyInfo(String JavaDoc url, Properties JavaDoc info) throws SQLException {
86         /**@todo: Implement this java.sql.Driver method*/
87         throw new java.lang.UnsupportedOperationException JavaDoc("Method getPropertyInfo() not yet implemented.");
88     }
89     
90     
91     public int getMajorVersion() {
92         return 0;
93     }
94     
95     
96     public int getMinorVersion() {
97         return 16;
98     }
99     
100     
101     public boolean jdbcCompliant() {
102         return true;
103     }
104 }
Popular Tags