1 |
package dk.daoas.fulddaekning; |
package dk.daoas.fulddaekning; |
2 |
|
|
3 |
|
import java.io.IOException; |
4 |
import java.sql.Connection; |
import java.sql.Connection; |
5 |
|
import java.sql.DriverManager; |
6 |
import java.sql.PreparedStatement; |
import java.sql.PreparedStatement; |
7 |
import java.sql.ResultSet; |
import java.sql.ResultSet; |
8 |
import java.sql.SQLException; |
import java.sql.SQLException; |
9 |
import java.util.ArrayList; |
import java.util.ArrayList; |
10 |
|
import java.util.HashMap; |
11 |
import java.util.List; |
import java.util.List; |
12 |
|
import java.util.Properties; |
13 |
import java.util.Queue; |
import java.util.Queue; |
14 |
import java.util.concurrent.ConcurrentLinkedQueue; |
import java.util.concurrent.ConcurrentLinkedQueue; |
15 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
16 |
|
|
17 |
|
|
18 |
|
|
19 |
public class Database { |
public class Database { |
20 |
Logger logger = Logger.getLogger(Database.class.getName()); |
Logger logger = Logger.getLogger(Database.class.getName()); |
21 |
|
|
22 |
|
int batchCount = 0; |
23 |
|
|
24 |
Connection conn; |
Connection conn; |
25 |
PreparedStatement saveStmt; |
PreparedStatement saveStmt; |
26 |
|
|
27 |
|
Adresse alleAdresser[]; |
28 |
|
|
29 |
|
private HashMap<String,BoundingBox> bbCache = new HashMap<String,BoundingBox>(); |
30 |
|
|
31 |
public Database(Connection conn) throws SQLException { |
public Database(SafeProperties conf) throws SQLException,IOException { |
32 |
this.conn = conn; |
this.conn = getConnection( conf ); |
33 |
|
|
34 |
String sql = "INSERT INTO fulddaekning.afstand_anden_rute_thn (orgId,orgPostnr, orgAdresse,orgGadeid,orgHusnr,orgHusnrBogstav,orgLatitude,orgLongitude,orgRute,id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,afstand,`timestamp`) "+ |
String sql = "INSERT INTO fulddaekning.afstand_anden_rute_ny (orgId,orgPostnr, orgAdresse,orgGadeid,orgHusnr,orgHusnrBogstav,orgLatitude,orgLongitude,orgRute,id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,afstand,`timestamp`) "+ |
35 |
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )"; |
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )"; |
36 |
|
|
37 |
saveStmt = conn.prepareStatement(sql); |
saveStmt = conn.prepareStatement(sql); |
38 |
|
|
39 |
|
} |
40 |
|
|
41 |
|
public void resetResultTable() throws SQLException { |
42 |
|
logger.info("Dropping old result table (if exists)"); |
43 |
|
String sql = "DROP TABLE IF EXISTS fulddaekning.afstand_anden_rute_ny"; |
44 |
|
conn.createStatement().executeUpdate(sql); |
45 |
|
|
46 |
|
logger.info("Create new result table"); |
47 |
|
sql = "CREATE TABLE fulddaekning.afstand_anden_rute_ny LIKE fulddaekning.afstand_anden_rute"; |
48 |
|
conn.createStatement().executeUpdate(sql); |
49 |
|
} |
50 |
|
|
51 |
|
public void renameResultTables() throws SQLException { |
52 |
|
Constants consts = Constants.getInstance(); |
53 |
|
String ext = consts.getTableExtension(); |
54 |
|
|
55 |
|
logger.info("Dropping old backup table (if exists)"); |
56 |
|
String sql = "DROP TABLE IF EXISTS fulddaekning.afstand_anden_rute_old" + ext; |
57 |
|
conn.createStatement().executeUpdate(sql); |
58 |
|
|
59 |
|
logger.info("Rename tables"); |
60 |
|
sql = "RENAME TABLE fulddaekning.afstand_anden_rute" + ext + " TO fulddaekning.afstand_anden_rute_old" + ext + ", fulddaekning.afstand_anden_rute_ny TO fulddaekning.afstand_anden_rute" + ext; |
61 |
|
|
62 |
|
logger.info("Executing: " + sql); |
63 |
|
conn.createStatement().executeUpdate(sql); |
64 |
} |
} |
65 |
|
|
66 |
public BoundingBox getBoundingbox(int postnr) throws SQLException { |
public BoundingBox getBoundingbox(String postnr) throws SQLException { |
67 |
|
BoundingBox bb = bbCache.get(postnr); |
68 |
|
if ( bb == null ) { |
69 |
|
bb = getBoundingboxFromDb(postnr); |
70 |
|
bbCache.put(postnr, bb); |
71 |
|
} else { |
72 |
|
logger.info("Serving BB from cache"); |
73 |
|
} |
74 |
|
|
75 |
|
return bb.clone();//never return the original / cached object |
76 |
|
} |
77 |
|
|
78 |
|
private BoundingBox getBoundingboxFromDb(String postnr) throws SQLException { |
79 |
|
String minPostnr = postnr.replace('x', '0'); |
80 |
|
String maxPostnr = postnr.replace('x', '9'); |
81 |
|
|
82 |
String sql = |
String sql = |
83 |
"select max(latitude) latmax, min(latitude) latmin, max(longitude) lngmax,min(longitude) lngmin " + |
"SELECT max(latitude) latmax, min(latitude) latmin, max(longitude) lngmax,min(longitude) lngmin " + |
84 |
"from fulddaekning.adressetabel WHERE postnr=? and rute is null;"; |
"FROM fulddaekning.adressetabel WHERE postnr BETWEEN ? and ? and rute is null;"; |
85 |
|
|
86 |
PreparedStatement stmt = conn.prepareStatement(sql); |
PreparedStatement stmt = conn.prepareStatement(sql); |
87 |
stmt.setInt(1, postnr); |
stmt.setString(1, minPostnr); |
88 |
|
stmt.setString(2, maxPostnr); |
89 |
|
|
90 |
ResultSet res = stmt.executeQuery(); |
ResultSet res = stmt.executeQuery(); |
91 |
res.next(); //query returnerer altid 1 række |
res.next(); //query returnerer altid 1 række |
92 |
|
|
93 |
BoundingBox bbox = new BoundingBox(); |
BoundingBox bbox = new BoundingBox(); |
94 |
bbox.latitudeMax = res.getDouble("latmax"); |
bbox.latitudeMax = res.getDouble("latmax"); |
95 |
bbox.latitudeMin = res.getDouble("latmin"); |
bbox.latitudeMin = res.getDouble("latmin"); |
96 |
bbox.longitudeMax = res.getDouble("lngmax"); |
bbox.longitudeMax = res.getDouble("lngmax"); |
97 |
bbox.longitudeMin = res.getDouble("lngmin"); |
bbox.longitudeMin = res.getDouble("lngmin"); |
98 |
|
|
99 |
res.close(); |
res.close(); |
100 |
stmt.close(); |
stmt.close(); |
101 |
|
|
102 |
return bbox; |
return bbox; |
103 |
} |
} |
104 |
|
|
105 |
public Queue<Adresse> hentIkkedaekkedeAdresser(int postnr) throws SQLException { |
|
106 |
ConcurrentLinkedQueue<Adresse> queue = new ConcurrentLinkedQueue<Adresse>(); |
|
107 |
|
public Queue<Adresse> hentIkkedaekkedeAdresser(String postnr) throws SQLException { |
108 |
|
|
109 |
String sql = "SELECT id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute FROM fulddaekning.adressetabel " + |
String minPostnr = postnr.replace('x', '0'); |
110 |
|
String maxPostnr = postnr.replace('x', '9'); |
111 |
|
|
112 |
|
ConcurrentLinkedQueue<Adresse> queue = new ConcurrentLinkedQueue<Adresse>(); |
113 |
|
|
114 |
|
String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " + |
115 |
|
"FROM fulddaekning.adressetabel a " + |
116 |
|
"LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " + |
117 |
"WHERE rute IS NULL " + //Ingen dækning |
"WHERE rute IS NULL " + //Ingen dækning |
118 |
"AND postnr=? " + |
"AND a.postnr BETWEEN ? AND ? " + |
119 |
"AND latitude IS NOT NULL " + |
"AND latitude IS NOT NULL " + |
120 |
"AND longitude IS NOT NULL " + |
"AND longitude IS NOT NULL " + |
121 |
"AND gadeid IS NOT NULL "; |
"AND gadeid IS NOT NULL " + |
122 |
|
"AND (a.distributor IS NULL OR a.distributor<>'LUKKET') "; |
123 |
PreparedStatement stmt = conn.prepareStatement(sql); |
PreparedStatement stmt = conn.prepareStatement(sql); |
124 |
stmt.setInt(1, postnr); |
stmt.setString(1, minPostnr); |
125 |
|
stmt.setString(2, maxPostnr); |
126 |
|
|
127 |
queue.addAll( hentAdresseListe( stmt ) ); |
queue.addAll( hentAdresseListe( stmt ) ); |
128 |
return queue; |
return queue; |
129 |
} |
} |
130 |
|
|
131 |
public List<Integer> hentPostnumre() throws SQLException { |
public List<String> hentPostnumre() throws SQLException { |
132 |
ArrayList<Integer> list = new ArrayList<Integer>(); |
ArrayList<String> list = new ArrayList<String>(); |
133 |
|
|
134 |
|
Constants consts = Constants.getInstance(); |
135 |
|
|
136 |
|
/* |
137 |
|
String sql = "SELECT postnr " + |
138 |
|
"FROM fulddaekning.adressetabel " + |
139 |
|
"WHERE postnr BETWEEN ? AND ? " + |
140 |
|
"AND rute is null " + // Træk kun liste på postnumre hvor der er ikke-dækkede adresser |
141 |
|
"GROUP BY postnr " + |
142 |
|
"ORDER by postnr"; |
143 |
|
*/ |
144 |
|
|
145 |
|
|
146 |
|
String sql = "SELECT rpad(left(postnr,?),'4', 'x') as postnr2 " + |
147 |
|
"FROM fulddaekning.adressetabel " + |
148 |
|
"WHERE postnr BETWEEN ? AND ? " + |
149 |
|
"AND rute is null " + // Trae kun liste paa postnumre hvor der er ikke-daekede adresser |
150 |
|
"AND (postnr NOT BETWEEN 3900 and 3999) " + //Skip alle groenlandske postnumre |
151 |
|
"GROUP BY postnr2 " + |
152 |
|
"ORDER by postnr2 "; |
153 |
|
|
154 |
String sql = "SELECT postnr FROM fulddaekning.adressetabel WHERE distributor = 'DAO' and rute is not null GROUP BY postnr ORDER by postnr"; |
|
155 |
|
|
156 |
PreparedStatement stmt = conn.prepareStatement(sql); |
PreparedStatement stmt = conn.prepareStatement(sql); |
157 |
|
//stmt.setString(1, Lookup.distributor ); |
158 |
|
|
159 |
|
stmt.setInt(1, consts.getPostnrGroup() ); |
160 |
|
|
161 |
|
stmt.setInt(2, consts.getMinPostnr()); |
162 |
|
stmt.setInt(3, consts.getMaxPostnr()); |
163 |
ResultSet res = stmt.executeQuery(); |
ResultSet res = stmt.executeQuery(); |
164 |
|
|
165 |
while (res.next()) { |
while (res.next()) { |
166 |
int postnr = res.getInt("postnr"); |
String postnr = res.getString("postnr2"); |
167 |
list.add(postnr); |
list.add(postnr); |
168 |
} |
} |
169 |
res.close(); |
res.close(); |
170 |
stmt.close(); |
stmt.close(); |
171 |
|
|
172 |
//list.add(8700); |
//list.add(8700); |
173 |
|
|
174 |
return list; |
return list; |
175 |
} |
} |
176 |
|
|
177 |
public ArrayList<Adresse> hentDaekkedeAdresser( BoundingBox bbox) throws SQLException { |
@Deprecated |
178 |
String sql = "SELECT id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute FROM fulddaekning.adressetabel " + |
public Adresse[] hentDaekkedeAdresser( BoundingBox bbox) throws SQLException { |
179 |
|
long start = System.currentTimeMillis(); |
180 |
|
String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " + |
181 |
|
"FROM fulddaekning.adressetabel a " + |
182 |
|
"LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " + |
183 |
"WHERE rute IS NOT NULL " + |
"WHERE rute IS NOT NULL " + |
184 |
"AND latitude BETWEEN ? AND ? " + |
"AND latitude BETWEEN ? AND ? " + |
185 |
"AND longitude BETWEEN ? AND ? " + |
"AND longitude BETWEEN ? AND ? " + |
186 |
"AND distributor = 'DAO' "; |
"AND a.distributor = ? "; |
187 |
|
|
188 |
// Forward only + concur_read_only + fetchsize tvinger driver til at hente en række af gangen (bedre performance ved store result sets) |
// Forward only + concur_read_only + fetchsize tvinger driver til at hente en række af gangen (bedre performance ved store result sets) |
189 |
// Se http://dev.mysql.com/doc/connector-j/en/connector-j-reference-implementation-notes.html |
// Se http://dev.mysql.com/doc/connector-j/en/connector-j-reference-implementation-notes.html |
190 |
//PreparedStatement stmt = conn.prepareStatement(sql); |
//PreparedStatement stmt = conn.prepareStatement(sql); |
191 |
PreparedStatement stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); |
PreparedStatement stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); |
192 |
stmt.setFetchSize(Integer.MIN_VALUE); |
stmt.setFetchSize(Integer.MIN_VALUE); |
193 |
|
|
194 |
stmt.setDouble(1, bbox.latitudeMin); |
stmt.setDouble(1, bbox.latitudeMin); |
195 |
stmt.setDouble(2, bbox.latitudeMax); |
stmt.setDouble(2, bbox.latitudeMax); |
196 |
stmt.setDouble(3, bbox.longitudeMin); |
stmt.setDouble(3, bbox.longitudeMin); |
197 |
stmt.setDouble(4, bbox.longitudeMax); |
stmt.setDouble(4, bbox.longitudeMax); |
198 |
|
stmt.setString(5, LookupMain.distributor); |
|
return hentAdresseListe( stmt ); |
|
|
|
|
|
} |
|
199 |
|
|
200 |
|
List<Adresse> list = hentAdresseListe( stmt ); |
201 |
|
long stop = System.currentTimeMillis(); |
202 |
|
logger.info("Elapsed DB: " + (stop - start)); |
203 |
|
return list.toArray( new Adresse[ list.size() ] ); |
204 |
|
} |
205 |
|
|
206 |
|
public Adresse[] hentDaekkedeAdresserCache( BoundingBox bbox) { |
207 |
|
long start = System.currentTimeMillis(); |
208 |
|
ArrayList<Adresse> list = new ArrayList<Adresse>(); |
209 |
|
for (Adresse a : alleAdresser) { |
210 |
|
if ( a.latitude > bbox.latitudeMin && a.latitude< bbox.latitudeMax && a.longitude> bbox.longitudeMin && a.longitude < bbox.longitudeMax) { |
211 |
|
list.add(a); |
212 |
|
} |
213 |
|
} |
214 |
|
long stop = System.currentTimeMillis(); |
215 |
|
logger.info("Elapsed cache: " + (stop - start)); |
216 |
|
return list.toArray( new Adresse[ list.size() ] ); |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
|
public Adresse[] hentAlleDaekkedeAdresser() throws SQLException { |
221 |
|
if ( alleAdresser == null ) { |
222 |
|
String sql = "SELECT id,a.postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,p.distributor as ho " + |
223 |
|
"FROM fulddaekning.adressetabel a " + |
224 |
|
"LEFT JOIN bogleveringer.postnummerdistributor p on (a.postnr=p.postnr) " + |
225 |
|
"WHERE rute IS NOT NULL " + |
226 |
|
"AND latitude IS NOT NULL " + |
227 |
|
"AND longitude IS NOT NULL " + |
228 |
|
"AND a.distributor = ? "; |
229 |
|
|
230 |
|
// Forward only + concur_read_only + fetchsize tvinger driver til at hente en række af gangen (bedre performance ved store result sets) |
231 |
|
// Se http://dev.mysql.com/doc/connector-j/en/connector-j-reference-implementation-notes.html |
232 |
|
//PreparedStatement stmt = conn.prepareStatement(sql); |
233 |
|
PreparedStatement stmt = conn.prepareStatement(sql, java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); |
234 |
|
stmt.setFetchSize(Integer.MIN_VALUE); |
235 |
|
|
236 |
|
stmt.setString(1, LookupMain.distributor); |
237 |
|
|
238 |
|
List<Adresse> list = hentAdresseListe( stmt ); |
239 |
|
alleAdresser = list.toArray( new Adresse[ list.size() ] ); |
240 |
|
} |
241 |
|
return alleAdresser; |
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
public synchronized void gemResultat(Adresse orgAdresse, Adresse bedsteAdresse, double bedsteAfstand) throws SQLException { |
public synchronized void gemResultat(Adresse orgAdresse, Adresse bedsteAdresse, double bedsteAfstand) throws SQLException { |
247 |
/*String sql = "INSERT INTO fulddaekning.afstand_anden_rute_thn (orgId,orgPostnr, orgAdresse,orgGadeid,orgHusnr,orgHusnrBogstav,orgLatitude,orgLongitude,orgRute,id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,afstand,`timestamp`) "+ |
/*String sql = "INSERT INTO fulddaekning.afstand_anden_rute_thn (orgId,orgPostnr, orgAdresse,orgGadeid,orgHusnr,orgHusnrBogstav,orgLatitude,orgLongitude,orgRute,id,postnr,adresse,gadeid,husnr,husnrbogstav,latitude,longitude,rute,afstand,`timestamp`) "+ |
248 |
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )"; |
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )"; |
249 |
|
|
250 |
PreparedStatement saveStmt = conn.prepareStatement(sql);*/ |
PreparedStatement saveStmt = conn.prepareStatement(sql);*/ |
251 |
|
|
252 |
saveStmt.setInt(1, orgAdresse.id); |
saveStmt.setInt(1, orgAdresse.id); |
253 |
saveStmt.setInt(2, orgAdresse.postnr); |
saveStmt.setInt(2, orgAdresse.postnr); |
254 |
saveStmt.setString(3, orgAdresse.adresse); |
saveStmt.setString(3, orgAdresse.adresse); |
258 |
saveStmt.setDouble(7, orgAdresse.latitude); |
saveStmt.setDouble(7, orgAdresse.latitude); |
259 |
saveStmt.setDouble(8, orgAdresse.longitude); |
saveStmt.setDouble(8, orgAdresse.longitude); |
260 |
saveStmt.setString(9, orgAdresse.rute); |
saveStmt.setString(9, orgAdresse.rute); |
261 |
|
|
262 |
|
|
263 |
saveStmt.setInt(10, bedsteAdresse.id); |
saveStmt.setInt(10, bedsteAdresse.id); |
264 |
saveStmt.setInt(11, bedsteAdresse.postnr); |
saveStmt.setInt(11, bedsteAdresse.postnr); |
265 |
saveStmt.setString(12, bedsteAdresse.adresse); |
saveStmt.setString(12, bedsteAdresse.adresse); |
269 |
saveStmt.setDouble(16, bedsteAdresse.latitude); |
saveStmt.setDouble(16, bedsteAdresse.latitude); |
270 |
saveStmt.setDouble(17, bedsteAdresse.longitude); |
saveStmt.setDouble(17, bedsteAdresse.longitude); |
271 |
saveStmt.setString(18, bedsteAdresse.rute); |
saveStmt.setString(18, bedsteAdresse.rute); |
272 |
|
|
273 |
saveStmt.setDouble(19, bedsteAfstand); |
saveStmt.setDouble(19, bedsteAfstand); |
274 |
|
|
275 |
saveStmt.executeUpdate(); |
saveStmt.addBatch(); |
276 |
saveStmt.clearParameters(); |
batchCount++; |
277 |
|
if (batchCount >= 100) { |
278 |
|
saveStmt.executeBatch(); |
279 |
|
batchCount = 0; |
280 |
|
} |
281 |
|
//saveStmt.executeUpdate(); |
282 |
|
//saveStmt.clearParameters(); |
283 |
|
|
284 |
//saveStmt.close(); |
//saveStmt.close(); |
|
|
|
285 |
} |
} |
286 |
|
|
287 |
|
public synchronized void saveBatch() throws SQLException{ |
288 |
|
saveStmt.executeBatch(); |
289 |
|
batchCount = 0; |
290 |
|
} |
291 |
|
|
292 |
|
|
293 |
|
|
294 |
protected ArrayList<Adresse> hentAdresseListe(PreparedStatement stmt) throws SQLException{ |
protected ArrayList<Adresse> hentAdresseListe(PreparedStatement stmt) throws SQLException{ |
295 |
ArrayList<Adresse> list = new ArrayList<Adresse>( 30000 ); |
ArrayList<Adresse> list = new ArrayList<Adresse>( 1000000 ); |
296 |
|
|
297 |
//logger.info("Starting query"); |
//logger.info("Starting query"); |
298 |
ResultSet res = stmt.executeQuery(); |
ResultSet res = stmt.executeQuery(); |
299 |
//logger.info("Starting exec query done"); |
//logger.info("Starting exec query done"); |
300 |
|
|
301 |
while (res.next()) { |
while (res.next()) { |
302 |
Adresse adr = new Adresse(); |
Adresse adr = new Adresse(); |
303 |
|
|
304 |
|
/* |
305 |
adr.id = res.getInt("id"); |
adr.id = res.getInt("id"); |
306 |
adr.postnr = res.getInt("postnr"); |
adr.postnr = res.getInt("postnr"); |
307 |
adr.adresse = res.getString("adresse"); |
adr.adresse = res.getString("adresse"); |
311 |
adr.latitude = res.getDouble("latitude"); |
adr.latitude = res.getDouble("latitude"); |
312 |
adr.longitude = res.getDouble("longitude"); |
adr.longitude = res.getDouble("longitude"); |
313 |
adr.rute = res.getString("rute"); |
adr.rute = res.getString("rute"); |
314 |
|
adr.ho = res.getInt("ho"); |
315 |
|
*/ |
316 |
|
|
317 |
|
adr.id = res.getInt(1); |
318 |
|
adr.postnr = res.getInt(2); |
319 |
|
adr.adresse = res.getString(3); |
320 |
|
adr.gadeid = res.getInt(4); |
321 |
|
adr.husnr = res.getInt(5); |
322 |
|
adr.husnrbogstav = res.getString(6); |
323 |
|
adr.latitude = res.getDouble(7); |
324 |
|
adr.longitude = res.getDouble(8); |
325 |
|
adr.rute = res.getString(9); |
326 |
|
adr.ho = res.getInt(10); |
327 |
|
|
328 |
list.add(adr); |
list.add(adr); |
329 |
|
|
330 |
//logger.info( "Adress:" + adr); |
//logger.info( "Adress:" + adr); |
331 |
} |
} |
332 |
|
|
333 |
res.close(); |
res.close(); |
334 |
stmt.close(); |
stmt.close(); |
335 |
|
|
336 |
return list; |
return list; |
337 |
} |
} |
338 |
|
|
339 |
|
public Connection getConnection(SafeProperties conf) throws SQLException, IOException { |
340 |
|
|
341 |
|
String db_host = conf.getSafeProperty("DB_HOST"); |
342 |
|
String db_user = conf.getSafeProperty("DB_USER"); |
343 |
|
String db_pass = conf.getSafeProperty("DB_PASS"); |
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
Connection conn = null; |
349 |
|
Properties connectionProps = new Properties(); |
350 |
|
connectionProps.put("user", db_user); |
351 |
|
connectionProps.put("password", db_pass); |
352 |
|
|
353 |
|
//For debug output, tilføj denne til JDBC url'en: &profileSQL=true |
354 |
|
conn = DriverManager.getConnection( |
355 |
|
"jdbc:mysql://" + |
356 |
|
db_host + |
357 |
|
":3306/?rewriteBatchedStatements=true", |
358 |
|
connectionProps); |
359 |
|
logger.info("Connected to database"); |
360 |
|
return conn; |
361 |
|
} |
362 |
|
|
363 |
} |
} |