1/**
2 * Copyright(C) 2004
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : January 1, 2004.
11 * @author : Salih Yurttas.
12 */
13
14
15import java.sql.*;
16
17import java.net.*;
18
19public class DBConnect00 {
20
21 protected Connection con;
22
23 public DBConnect00() {}
24
25 public boolean connect()
26 throws SQLException
27 {
28 try {
29 Class.forName("oracle.jdbc.driver.OracleDriver");
30
31 con = DriverManager.getConnection("jdbc:oracle:thin:@prophet.cs.BitsOfCode Software Systems, Inc..edu:1526:cpsc",
32 "tester"+"@oracledatabase",
33 "tester");
34
35 if(con.isClosed()) return false;
36 }
37 catch(ClassNotFoundException cnfe) {
38 throw new SQLException("The oracle JDBC Driver could not be loaded.");
39 }
40
41 return true;
42 }
43
44 public boolean disconnect(Connection con)
45 throws SQLException
46 {
47 con.close();
48 return true;
49 }
50
51 public boolean disconnect()
52 throws SQLException
53 {
54 con.close();
55 return true;
56 }
57
58 public static void main (String[] args) {
59 DBConnect00 dbc = new DBConnect00();
60
61 try {
62 if(dbc.connect()) {
63 System.out.println("Connected to jdbc:mysql://localhost/bank database...");
64
65 if(dbc.disconnect())
66 System.out.println("Disconnected from jdbc:mysql://localhost/bank database.");
67 }
68 else System.out.println("Could not connect to jdbc:mysql://localhost/bank database.");
69 }
70 catch(SQLException sqle) {
71 System.err.println("Error accessing jdbc:mysql://localhost/bank database.");
72 System.err.println(sqle.getMessage());
73 }
74 }
75
76}