D:\JavaFrameworks\InsuranceFramework\src\java\db_adapter\CHECK_Constraint.java |
1
2
3
4
5
6 package db_adapter;
7
8
9
10 @author
11
12
13 import java.io.*;
14 import java.sql.Connection;
15 import java.sql.DriverManager;
16 import java.sql.PreparedStatement;
17 import java.sql.ResultSet;
18 import java.sql.SQLException;
19 import java.util.ArrayList;
20 import java.util.Hashtable;
21 import java.util.MissingResourceException;
22 import java.util.ResourceBundle;
23
24
25
26
27 import utils.*;
28 import constants.*;
29
30
31 public class CHECK_Constraint
32 {
33 Connection localConnection = null;
34
35 public CHECK_Constraint()
36 {
37 BD_Connector localBD_Connector = new BD_Connector();
38 localConnection = localBD_Connector.getConnection();
39 }
40
41
42
43 public int alterTableWithCHECKConstrain(String passedTableName, String passedID, int passedValue)
44 {
45 if(null == localConnection)
46 return(Constants.ERROR_RUN);
47 PreparedStatement localPreparedStatement = null;
48
49 try
50 {
51
52
53
54 String qryString = "";
55 String table_1 = DatabaseKeysPropertyManager.getParameter(passedTableName);
56
57 qryString = "ALTER TABLE "
58 + table_1
59 + " ADD "
60 + "CHECK "
61 + " ("
62 + passedID
63 + ">"
64 + passedValue
65 + ")";
66 localPreparedStatement = localConnection.prepareStatement(qryString);
67 localPreparedStatement.executeQuery();
68 localPreparedStatement.close();
69 }
70 catch(MissingResourceException eMissingResourceException)
71 {
72 eMissingResourceException.printStackTrace();
73 return(Constants.ERROR_RUN);
74 }
75 catch(SQLException eSQLException)
76 {
77 eSQLException.printStackTrace();
78 return(Constants.ERROR_RUN);
79 }
80
81 return(Constants.NORMAL_RUN);
82 }
83
84
85
86 public int CreateTableWithCHECKConstrain(String passedTableName, String passedID, int passedMonth)
87 {
88 if(null == localConnection)
89 return(Constants.ERROR_RUN);
90 PreparedStatement localPreparedStatement = null;
91
92 try
93 {
94
95
96
97
98
99
100 String qryString = "";
101 String table_1 = DatabaseKeysPropertyManager.getParameter(passedTableName);
102
103 qryString = "CREATE TABLE "
104 + table_1
105 + "(ID INTEGER REFERENCES STATION(ID), "
106 + "MONTH INTEGER "
107 + " CHECK "
108 + " (MONTH BETWEEN 1 AND 12), "
109 + "TEMP_F REAL "
110 + "CHECK "
111 + " (TEMP_F BETWEEN -80 AND 150), "
112 + "RAIN_I REAL "
113 + " CHECK "
114 + " (RAIN_I BETWEEN 0 AND 100), "
115 + "PRIMARY KEY ("
116 + passedID
117 + ", "
118 + passedMonth
119 + ");";
120 localPreparedStatement = localConnection.prepareStatement(qryString);
121 localPreparedStatement.executeQuery();
122 localPreparedStatement.close();
123 }
124 catch(MissingResourceException eMissingResourceException)
125 {
126 eMissingResourceException.printStackTrace();
127 return(Constants.ERROR_RUN);
128 }
129 catch(SQLException eSQLException)
130 {
131 eSQLException.printStackTrace();
132 return(Constants.ERROR_RUN);
133 }
134
135 return(Constants.NORMAL_RUN);
136 }
137
138 }
139
140