KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xeus > bottomline > Bottomline


1 /**
2  * Bottomline
3  * A JDBC Bridge API to load multiple database drivers from JAR files
4  *
5  * Copyright (C) 2006 Technology N
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * @author Kamran Zafar
22  *
23  * Contact Info:
24  * Email: kamran@technology-n.com
25  * xeus.man@gmail.com
26  */

27
28 /*
29  * Bottomline.java
30  * Created on Sep 9, 2006
31  */

32 package xeus.bottomline;
33
34 import java.sql.Connection JavaDoc;
35 import java.sql.DriverManager JavaDoc;
36 import java.sql.ResultSet JavaDoc;
37 import java.sql.SQLException JavaDoc;
38 import java.sql.Statement JavaDoc;
39 import java.util.Properties JavaDoc;
40
41 /**
42  * @author Kamran Zafar
43  *
44  */

45 public class Bottomline {
46
47     private Properties JavaDoc props;
48
49     /**
50      * @param jar
51      * @param className
52      * @param url
53      * @param user
54      * @param password
55      * @throws ClassNotFoundException
56      * @throws InstantiationException
57      * @throws IllegalAccessException
58      * @throws SQLException
59      */

60     public Bottomline(String JavaDoc jar, String JavaDoc className, String JavaDoc url, String JavaDoc user,
61             String JavaDoc password) throws ClassNotFoundException JavaDoc,
62             InstantiationException JavaDoc, IllegalAccessException JavaDoc, SQLException JavaDoc {
63         props = new Properties JavaDoc();
64         props.put(BottomlineConstants.USER, user);
65         props.put(BottomlineConstants.PASSWORD, password);
66         props.put(BottomlineConstants.DRIVER_JAR, jar);
67         props.put(BottomlineConstants.DRIVER_CLASS, className);
68         props.put("url", url);
69     }
70
71     /**
72      * @param props
73      */

74     public Bottomline(Properties JavaDoc props) {
75         this.props = props;
76     }
77
78     /**
79      * @return
80      * @throws SQLException
81      * @throws InstantiationException
82      * @throws IllegalAccessException
83      * @throws ClassNotFoundException
84      */

85     public Connection JavaDoc getConnection() throws SQLException JavaDoc,
86             InstantiationException JavaDoc, IllegalAccessException JavaDoc,
87             ClassNotFoundException JavaDoc {
88         Class.forName("xeus.bottomline.BottomlineDriver");
89         return DriverManager.getConnection(props
90                 .getProperty(BottomlineConstants.CONNECTION_URL), props);
91     }
92
93     /**
94      * Test
95      */

96     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
97         Class.forName("xeus.bottomline.BottomlineDriver", true, Thread
98                 .currentThread().getContextClassLoader());
99         Properties JavaDoc props = new Properties JavaDoc();
100         props.put("user", "root");
101         props.put("password", "root");
102         props
103                 .put(
104                         "jar",
105                         "D:\\software\\stuff 4\\mysql-connector-java-5.0.3\\"
106                                 + "mysql-connector-java-5.0.3\\mysql-connector-java-5.0.3-bin.jar");
107         props.put("class", "com.mysql.jdbc.Driver");
108
109         String JavaDoc jar = "D:\\software\\stuff 4\\mysql-connector-java-5.0.3\\"
110                 + "mysql-connector-java-5.0.3\\mysql-connector-java-5.0.3-bin.jar";
111
112         // Connection conn = DriverManager.getConnection(
113
// "jdbc:bottomline:mysql://localhost:3306/timesheet", props);
114

115         Connection JavaDoc conn = DriverManager
116                 .getConnection("jdbc:bottomline:mysql://localhost:3306/timesheet?user=root&password=root&jar="
117                         + jar + "&class=com.mysql.jdbc.Driver");
118
119         // Connection conn = DriverManager.getConnection(
120
// "jdbc:bottomline:mysql://localhost:3306/timesheet?jar=" + jar
121
// + "&class=com.mysql.jdbc.Driver", "root", "root");
122

123         Statement JavaDoc s = conn.createStatement();
124         ResultSet JavaDoc rs = s.executeQuery("SELECT * FROM pts_worker");
125
126         while (rs.next())
127             System.out.println(rs.getString("wname"));
128
129         rs.close();
130         s.close();
131         // conn.close();
132

133         Properties JavaDoc props1 = new Properties JavaDoc();
134         props1.put("user", "root");
135         props1.put("password", "root");
136         props1.put("class", "com.mysql.jdbc.Driver");
137         props1.put("jar",
138                 "D:\\software\\mysql-connector-java-2.0.14\\mysql-connector-java-2.0.14\\"
139                         + "mysql-connector-java-2.0.14-bin.jar");
140
141         try {
142             Connection JavaDoc conn1 = DriverManager.getConnection(
143                     "jdbc:bottomline:mysql://localhost:3306/timesheet", props1);
144
145             Statement JavaDoc s1 = conn1.createStatement();
146             ResultSet JavaDoc rs1 = s1.executeQuery("SELECT * FROM pts_worker");
147
148             while (rs1.next())
149                 System.out.println(rs1.getString("wname"));
150
151             rs1.close();
152             s1.close();
153             conn1.close();
154         } catch (Exception JavaDoc e) {
155             e.printStackTrace(System.err);
156         }
157
158         // conn = DriverManager.getConnection(
159
// "jdbc:bottomline:mysql://localhost:3306/timesheet", props);
160

161         s = conn.createStatement();
162         rs = s.executeQuery("SELECT * FROM pts_worker");
163
164         while (rs.next())
165             System.out.println(rs.getString("wname"));
166
167         rs.close();
168         s.close();
169         conn.close();
170     }
171 }
172
Popular Tags