1    package com.instantbank.collections.util;
2    
3    import java.sql.Connection;
4    import java.sql.SQLException;
5    import java.sql.Statement;
6    import javax.naming.NamingException;
7    
8    public class DataAccess {
9      protected java.sql.Connection connection;
10   
11   
12     public boolean connect() throws NamingException, SQLException {
13       connection = ServiceLocator.instance().getConnection();
14       return true;
15     }
16   
17   
18     public boolean disconnect() {
19       try {
20         if(connection != null) {
21           connection.close();
22         }
23         connection = null;
24       }
25       catch(SQLException e) {
26       }
27       return true;
28     }
29   
30   
31     public Connection getConnection() {
32       return connection;
33     }
34   
35   
36     public int makeInsert(String query) throws SQLException {
37       Statement sentence;
38       int modifiedRows = 0;
39       sentence = connection.createStatement();
40       modifiedRows = sentence.executeUpdate(query);
41       sentence.close();
42       return modifiedRows;
43     }
44   
45   
46     public int makeUpdate(String query) throws SQLException {
47       Statement sentence;
48       int modifiedRows = 0;
49       sentence = connection.createStatement();
50       modifiedRows = sentence.executeUpdate(query);
51       sentence.close();
52       return modifiedRows;
53     }
54   
55   
56   
57     public int makeDelete(String query) throws SQLException {
58       Statement sentence;
59       int modifiedRows = 0;
60   
61       sentence = connection.createStatement();
62       modifiedRows = sentence.executeUpdate(query);
63       sentence.close();
64       return modifiedRows;
65     }
66   }
67   
68