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