D:\JavaFrameworks\InsuranceFramework\src\java\db_adapter\DeleteRowsFromTables.java |
1
2
3
4
5
6 package db_adapter;
7
8
9
10 @author
11
12 import java.io.*;
13 import java.sql.Connection;
14 import java.sql.DriverManager;
15 import java.sql.PreparedStatement;
16 import java.sql.ResultSet;
17 import java.sql.SQLException;
18 import java.util.ArrayList;
19 import java.util.Hashtable;
20 import java.util.MissingResourceException;
21 import java.util.ResourceBundle;
22
23
24
25
26 import utils.*;
27 import constants.*;
28
29 public class DeleteRowsFromTables
30 {
31 Connection localConnection = null;
32
33 public DeleteRowsFromTables()
34 {
35 BD_Connector localBD_Connector = new BD_Connector();
36 localConnection = localBD_Connector.getConnection();
37 }
38
39
40
41 public int deleteOneTableRow(String passedTableName, String name, String email)
42 {
43 if(null == localConnection)
44 return(Constants.ERROR_RUN);
45 PreparedStatement localPreparedStatement = null;
46
47
48
49
50
51
52
53 try
54 {
55 String qryString = "";
56 String tableName = DatabaseKeysPropertyManager.getParameter(passedTableName);
57
58 qryString = "DELETE FROM "
59 + passedTableName
60 + " WHERE some_column="
61 + name
62 + " AND "
63 + "EMAIL="
64 + email;
65 localPreparedStatement = localConnection.prepareStatement(qryString);
66 localPreparedStatement.executeQuery();
67 localPreparedStatement.close();
68 }
69 catch(MissingResourceException eMissingResourceException)
70 {
71 eMissingResourceException.printStackTrace();
72 return(Constants.ERROR_RUN);
73 }
74 catch(SQLException eSQLException)
75 {
76 eSQLException.printStackTrace();
77 return(Constants.ERROR_RUN);
78 }
79 return(Constants.NORMAL_RUN);
80 }
81
82
83
84 public int deleteEnitreTable(String passedTableName)
85 {
86 if(null == localConnection)
87 return(Constants.ERROR_RUN);
88 PreparedStatement localPreparedStatement = null;
89
90
91
92
93
94
95
96
97
98 try
99 {
100 String qryString = "";
101 String tableName = DatabaseKeysPropertyManager.getParameter(passedTableName);
102
103 qryString = "DELETE * FROM "
104 + passedTableName;
105 localPreparedStatement = localConnection.prepareStatement(qryString);
106 localPreparedStatement.executeQuery();
107 localPreparedStatement.close();
108 }
109 catch(MissingResourceException eMissingResourceException)
110 {
111 eMissingResourceException.printStackTrace();
112 return(Constants.ERROR_RUN);
113 }
114 catch(SQLException eSQLException)
115 {
116 eSQLException.printStackTrace();
117 return(Constants.ERROR_RUN);
118 }
119 return(Constants.NORMAL_RUN);
120 }
121
122
123
124 public int truncateDataFromTable(String passedTableName)
125 {
126 if(null == localConnection)
127 return(Constants.ERROR_RUN);
128 PreparedStatement localPreparedStatement = null;
129
130
131
132
133
134
135 try
136 {
137 String qryString = "";
138 String tableName = DatabaseKeysPropertyManager.getParameter(passedTableName);
139
140 qryString = "TRUNCATE TABLE "
141 + passedTableName;
142 localPreparedStatement = localConnection.prepareStatement(qryString);
143 localPreparedStatement.executeQuery();
144 localPreparedStatement.close();
145 }
146 catch(MissingResourceException eMissingResourceException)
147 {
148 eMissingResourceException.printStackTrace();
149 return(Constants.ERROR_RUN);
150 }
151 catch(SQLException eSQLException)
152 {
153 eSQLException.printStackTrace();
154 return(Constants.ERROR_RUN);
155 }
156 return(Constants.NORMAL_RUN);
157 }
158
159
160
161 public int dropBD_Table(String passedTableName)
162 {
163 if(null == localConnection)
164 return(Constants.ERROR_RUN);
165 PreparedStatement localPreparedStatement = null;
166
167
168
169
170
171
172
173 try
174 {
175 String qryString = "";
176 String tableName = DatabaseKeysPropertyManager.getParameter(passedTableName);
177
178 qryString = "DROP "
179 + passedTableName;
180 localPreparedStatement = localConnection.prepareStatement(qryString);
181 localPreparedStatement.executeQuery();
182 localPreparedStatement.close();
183 }
184 catch(MissingResourceException eMissingResourceException)
185 {
186 eMissingResourceException.printStackTrace();
187 return(Constants.ERROR_RUN);
188 }
189 catch(SQLException eSQLException)
190 {
191 eSQLException.printStackTrace();
192 return(Constants.ERROR_RUN);
193 }
194 return(Constants.NORMAL_RUN);
195 }
196 }
197
198