KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > util > DriverListUtil


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.db.util;
21
22 import java.util.LinkedList JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Set JavaDoc;
25 import java.util.TreeSet JavaDoc;
26 import java.util.Vector JavaDoc;
27
28 import org.netbeans.api.db.explorer.JDBCDriver;
29 import org.netbeans.api.db.explorer.JDBCDriverManager;
30
31 public class DriverListUtil {
32
33     private static List JavaDoc drivers = new LinkedList JavaDoc();
34     private static List JavaDoc urls = new LinkedList JavaDoc();
35     private static List JavaDoc names = new LinkedList JavaDoc();
36
37     //private default constructor -> singleton
38
private DriverListUtil() {
39     }
40
41     static {
42         names.add("IBM DB2 (net)");
43         drivers.add("COM.ibm.db2.jdbc.net.DB2Driver");
44         urls.add("jdbc:db2://<HOST>:<PORT>/<DB>");
45
46         names.add("IBM DB2 (local)");
47         drivers.add("COM.ibm.db2.jdbc.app.DB2Driver");
48         urls.add("jdbc:db2:<DB>");
49         
50         names.add("JDBC-ODBC Bridge");
51         drivers.add("sun.jdbc.odbc.JdbcOdbcDriver");
52         urls.add("jdbc:odbc:<DB>");
53         
54         names.add("Microsoft SQL Server (Weblogic driver)");
55         drivers.add("weblogic.jdbc.mssqlserver4.Driver");
56         urls.add("jdbc:weblogic:mssqlserver4:<DB>@<HOST>:<PORT>");
57         
58         names.add("Oracle"); //thin
59
drivers.add("oracle.jdbc.driver.OracleDriver");
60         urls.add("jdbc:oracle:thin:@<HOST>:<PORT>:<SID>");
61         
62         names.add("PointBase"); //Network Server
63
drivers.add("com.pointbase.jdbc.jdbcUniversalDriver");
64         urls.add("jdbc:pointbase://<HOST>[:<PORT>]/<DB>");
65
66         names.add("PointBase"); //Embedded Server
67
drivers.add("com.pointbase.jdbc.jdbcUniversalDriver");
68         urls.add("jdbc:pointbase://embedded[:<PORT>]/<DB>");
69         
70         names.add("PointBase"); //Mobile Edition
71
drivers.add("com.pointbase.jdbc.jdbcUniversalDriver");
72         urls.add("jdbc:pointbase:<DB>");
73         
74         names.add("Cloudscape");
75         drivers.add("COM.cloudscape.core.JDBCDriver");
76         urls.add("jdbc:cloudscape:<DB>");
77         
78         names.add("Cloudscape RMI");
79         drivers.add("RmiJdbc.RJDriver");
80         urls.add("jdbc:rmi://<HOST>:<PORT>/jdbc:cloudscape:<DB>");
81         
82         names.add("Java DB (Embedded)");
83         drivers.add("org.apache.derby.jdbc.EmbeddedDriver");
84         urls.add("jdbc:derby:<DB>");
85         
86         names.add("Java DB (Network)");
87         drivers.add("org.apache.derby.jdbc.ClientDriver");
88         urls.add("jdbc:derby://<HOST>[:<PORT>]/databaseName[;attr1=value1[;...]]");
89         
90         names.add("Apache Derby (Net)");
91         drivers.add("com.ibm.db2.jcc.DB2Driver");
92         urls.add("jdbc:derby:net://<HOST>[:<PORT>]/<DB>");
93         
94         names.add("Firebird (JCA/JDBC driver)");
95         drivers.add("org.firebirdsql.jdbc.FBDriver");
96         urls.add("jdbc:firebirdsql:[//<HOST>[:<PORT>]/]<DB>");
97         
98         names.add("FirstSQL/J"); //Enterprise Server Edition
99
drivers.add("COM.FirstSQL.Dbcp.DbcpDriver");
100         urls.add("jdbc:dbcp://<HOST>:<PORT>");
101         
102         names.add("FirstSQL/J"); //Professional Edition
103
drivers.add("COM.FirstSQL.Dbcp.DbcpDriver");
104         urls.add("jdbc:dbcp://local");
105         
106         names.add("IBM DB2 (DataDirect Connect for JDBC)");
107         drivers.add("com.ddtek.jdbc.db2.DB2Driver");
108         urls.add("jdbc:datadirect:db2://<HOST>:<PORT>[;databaseName=<DB>]");
109
110         names.add("IDS Server");
111         drivers.add("ids.sql.IDSDriver");
112         urls.add("jdbc:ids://<HOST>:<PORT>/conn?dsn='<ODBC_DSN_NAME>'");
113         
114         names.add("Informix Dynamic Server");
115         drivers.add("com.informix.jdbc.IfxDriver");
116         urls.add("jdbc:informix-sqli://<HOST>:<PORT>/<DB>:INFORMIXSERVER=<SERVER_NAME>");
117
118         names.add("Informix Dynamic Server (DataDirect Connect for JDBC)");
119         drivers.add("com.ddtek.jdbc.informix.InformixDriver");
120         urls.add("jdbc:datadirect:informix://<HOST>:<PORT>;informixServer=<SERVER_NAME>;databaseName=<DB>");
121         
122         names.add("InstantDB (v3.13 and earlier)");
123         drivers.add("jdbc.idbDriver");
124         urls.add("jdbc:idb:<DB>");
125         
126         names.add("InstantDB (v3.14 and later)");
127         drivers.add("org.enhydra.instantdb.jdbc.idbDriver");
128         urls.add("jdbc:idb:<DB>");
129         
130         names.add("Interbase (InterClient driver)");
131         drivers.add("interbase.interclient.Driver");
132         urls.add("jdbc:interbase://<HOST>/<DB>");
133         
134         names.add("HSQLDB"); //(server)
135
drivers.add("org.hsqldb.jdbcDriver");
136         urls.add("jdbc:hsqldb:hsql://<HOST>[:<PORT>]");
137         
138         names.add("HSQLDB"); //(standalone)
139
drivers.add("org.hsqldb.jdbcDriver");
140         urls.add("jdbc:hsqldb:<DB>");
141         
142         names.add("HSQLDB"); //(webserver)
143
drivers.add("org.hsqldb.jdbcDriver");
144         urls.add("jdbc:hsqldb:http://<HOST>[:<PORT>]");
145         
146         names.add("HSQLDB"); //(in-memory)
147
drivers.add("org.hsqldb.jdbcDriver");
148         urls.add("jdbc:hsqldb:.");
149         
150         names.add("Hypersonic SQL (v1.2 and earlier)");
151         drivers.add("hSql.hDriver");
152         urls.add("jdbc:HypersonicSQL:<DB>");
153         
154         names.add("Hypersonic SQL (v1.3 and later)");
155         drivers.add("org.hsql.jdbcDriver");
156         urls.add("jdbc:HypersonicSQL:<DB>");
157         
158         names.add("jTDS");
159         drivers.add("net.sourceforge.jtds.jdbc.Driver");
160         urls.add("jdbc:jtds:sqlserver://<server>[:<PORT>][/<DATABASE>]");
161         
162         names.add("jTDS");
163         drivers.add("net.sourceforge.jtds.jdbc.Driver");
164         urls.add("jdbc:jtds:sybase://<server>[:<PORT>][/<DATABASE>]");
165         
166         names.add("Mckoi SQL Database"); //(server)
167
drivers.add("com.mckoi.JDBCDriver");
168         urls.add("jdbc:mckoi://<HOST>[:<PORT>]");
169         
170         names.add("Mckoi SQL Database"); //(standalone)
171
drivers.add("com.mckoi.JDBCDriver");
172         urls.add("jdbc:mckoi:local://<DB>");
173         
174         names.add("Microsoft SQL Server (DataDirect Connect for JDBC)");
175         drivers.add("com.ddtek.jdbc.sqlserver.SQLServerDriver");
176         urls.add("jdbc:datadirect:sqlserver://<HOST>:<PORT>[;databaseName=<DB>]");
177         
178         names.add("Microsoft SQL Server (JTurbo driver)");
179         drivers.add("com.ashna.jturbo.driver.Driver");
180         urls.add("jdbc:JTurbo://<HOST>:<PORT>/<DB>");
181         
182         names.add("Microsoft SQL Server (Sprinta driver)");
183         drivers.add("com.inet.tds.TdsDriver");
184         urls.add("jdbc:inetdae:<HOST>:<PORT>?database=<DB>");
185         
186         names.add("Microsoft SQL Server 2000 (Microsoft driver)");
187         drivers.add("com.microsoft.jdbc.sqlserver.SQLServerDriver");
188         urls.add("jdbc:microsoft:sqlserver://<HOST>:<PORT>[;DatabaseName=<DB>]");
189         
190         names.add("MySQL (Connector/J driver)");
191         drivers.add("com.mysql.jdbc.Driver");
192         urls.add("jdbc:mysql://<HOST>:<PORT>/<DB>");
193         
194         names.add("MySQL (MM.MySQL driver)");
195         drivers.add("org.gjt.mm.mysql.Driver");
196         urls.add("jdbc:mysql://<HOST>:<PORT>/<DB>");
197         
198         names.add("Oracle"); //OCI 8i
199
drivers.add("oracle.jdbc.driver.OracleDriver");
200         urls.add("jdbc:oracle:oci8:@<SID>");
201         
202         names.add("Oracle"); //OCI 9i
203
drivers.add("oracle.jdbc.driver.OracleDriver");
204         urls.add("jdbc:oracle:oci:@<SID>");
205         
206         names.add("Oracle (DataDirect Connect for JDBC)");
207         drivers.add("com.ddtek.jdbc.oracle.OracleDriver");
208         urls.add("jdbc:datadirect:oracle://<HOST>:<PORT>;SID=<SID>");
209         
210         names.add("PostgreSQL (v6.5 and earlier)");
211         drivers.add("postgresql.Driver");
212         urls.add("jdbc:postgresql://<HOST>:<PORT>/<DB>");
213         
214         names.add("PostgreSQL (v7.0 and later)");
215         drivers.add("org.postgresql.Driver");
216         urls.add("jdbc:postgresql://<HOST>:<PORT>/<DB>");
217         
218         names.add("Quadcap Embeddable Database");
219         drivers.add("com.quadcap.jdbc.JdbcDriver");
220         urls.add("jdbc:qed:<DB>");
221         
222         names.add("Sybase (jConnect 4.2 and earlier)");
223         drivers.add("com.sybase.jdbc.SybDriver");
224         urls.add("jdbc:sybase:Tds:<HOST>:<PORT>");
225         
226         names.add("Sybase (jConnect 5.2)");
227         drivers.add("com.sybase.jdbc2.jdbc.SybDriver");
228         urls.add("jdbc:sybase:Tds:<HOST>:<PORT>");
229         
230         names.add("Sybase (DataDirect Connect for JDBC)");
231         drivers.add("com.ddtek.jdbc.sybase.SybaseDriver");
232         urls.add("jdbc:datadirect:sybase://<HOST>:<PORT>[;databaseName=<DB>]");
233
234         // Following four entries for drivers to be included in Java Studio Enterprise 7 (Bow)
235
names.add("Microsoft SQL Server Driver");
236         drivers.add("com.sun.sql.jdbc.sqlserver.SQLServerDriver");
237         urls.add("jdbc:sun:sqlserver://server_name[:portNumber]");
238         
239         names.add("DB2 Driver");
240         drivers.add("com.sun.sql.jdbc.db2.DB2Driver");
241         urls.add("jdbc:sun:db2://server_name:portNumber;databaseName=DATABASENAME");
242         
243         names.add("Oracle Driver");
244         drivers.add("com.sun.sql.jdbc.oracle.OracleDriver");
245         urls.add("jdbc:sun:oracle://server_name[:portNumber][;SID=DATABASENAME]");
246         
247         names.add("Sybase Driver");
248         drivers.add("com.sun.sql.jdbc.sybase.SybaseDriver");
249         urls.add("jdbc:sun:sybase://server_name[:portNumber]");
250     }
251     
252     public static Set JavaDoc getDrivers() {
253         return new TreeSet JavaDoc(drivers);
254     }
255     
256     public static List JavaDoc getURLs(String JavaDoc drv) {
257         List JavaDoc ret = new LinkedList JavaDoc();
258         
259         for (int i = 0; i < drivers.size(); i++)
260             if (((String JavaDoc) drivers.get(i)).equals(drv))
261                 ret.add(urls.get(i));
262         
263         return ret;
264     }
265     
266     public static String JavaDoc getName(String JavaDoc drv) {
267         for (int i = 0; i < drivers.size(); i++)
268             if (((String JavaDoc) drivers.get(i)).equals(drv))
269                 return (String JavaDoc) names.get(i);
270         
271         return "";
272     }
273
274     public static String JavaDoc findFreeName(String JavaDoc name) {
275         String JavaDoc ret;
276         Vector JavaDoc names = new Vector JavaDoc();
277         JDBCDriver[] drivers = JDBCDriverManager.getDefault().getDrivers();
278         for (int i = 0; i < drivers.length; i++)
279             names.add(drivers[i].getDisplayName());
280         
281         if (names.contains(name))
282             for (int i = 1;;i++) {
283                 ret = name + " (" + i + ")";
284                 if (!names.contains(ret))
285                     return ret;
286             }
287         else
288             return name;
289     }
290 }
291
Popular Tags