Source code: gsoft/sql/SQLSrvCon.java
1 /*************************************************************************
2 Copyright (C) 2003 Steve Gee
3 stevesgee@cox.net
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *************************************************************************/
19
20 package gsoft.sql;
21
22 import java.io.*;
23 import java.sql.*;
24 import java.util.Properties;
25
26 public class SQLSrvCon implements ConnectionInterface{
27
28 private Connection sqlSrvConn;
29 private String DRIVER = "weblogic.jdbc.mssqlserver4.Driver";
30 private String URL = "jdbc:weblogic:mssqlserver4:";
31 private String USERNAME,PASSWORD,DATABASE,CONNECTION,SERVER,PORT;
32
33 public Connection getConn( String server,
34 String port,
35 String database,
36 String username,
37 String password)throws Exception{
38
39 USERNAME = username;
40 PASSWORD = password;
41 SERVER = server;
42 PORT = port;
43 DATABASE = database;
44
45 Properties props = new Properties();
46 props.put("user", username);
47 props.put("password", password);
48 props.put("server", database + "@" + server + ":" + port);
49 if(sqlSrvConn == null) {
50 Driver myDriver = (Driver)Class.forName("weblogic.jdbc.mssqlserver4.Driver").newInstance();
51 sqlSrvConn = myDriver.connect("jdbc:weblogic:mssqlserver4", props);
52 }//end if
53
54 return sqlSrvConn;
55 }//end initialize
56
57 public void closeConn() throws SQLException{
58 if(sqlSrvConn != null)
59 sqlSrvConn.close();
60 }//end closeConn
61
62 public String toString() {
63 String returnValue = null;
64 try {
65 returnValue = "User: " + USERNAME + "::Password: " + PASSWORD + "::Database: " + DATABASE + "::Server: " + SERVER + "::Port: " + PORT + "::Driver: " + DRIVER + "\n::Connection opened: " + !sqlSrvConn.isClosed();
66 } catch(Exception e) {
67 returnValue = e.toString();
68 }//end try-catch
69 return returnValue;
70 }//end toString
71
72 }//end class