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.List; |
import java.util.List; |
11 |
|
import java.util.Properties; |
12 |
import java.util.Queue; |
import java.util.Queue; |
13 |
import java.util.concurrent.ConcurrentLinkedQueue; |
import java.util.concurrent.ConcurrentLinkedQueue; |
14 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
21 |
Connection conn; |
Connection conn; |
22 |
PreparedStatement saveStmt; |
PreparedStatement saveStmt; |
23 |
|
|
24 |
public Database(Connection conn) throws SQLException { |
public Database(SafeProperties conf) throws SQLException,IOException { |
25 |
this.conn = conn; |
this.conn = getConnection( conf ); |
26 |
|
|
27 |
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`) "+ |
28 |
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )"; |
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )"; |
190 |
return list; |
return list; |
191 |
} |
} |
192 |
|
|
193 |
|
public Connection getConnection(SafeProperties conf) throws SQLException, IOException { |
194 |
|
|
195 |
|
String db_host = conf.getSafeProperty("DB_HOST"); |
196 |
|
String db_user = conf.getSafeProperty("DB_USER"); |
197 |
|
String db_pass = conf.getSafeProperty("DB_PASS"); |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
Connection conn = null; |
203 |
|
Properties connectionProps = new Properties(); |
204 |
|
connectionProps.put("user", db_user); |
205 |
|
connectionProps.put("password", db_pass); |
206 |
|
|
207 |
|
conn = DriverManager.getConnection( |
208 |
|
"jdbc:mysql://" + |
209 |
|
db_host + |
210 |
|
":3306/", |
211 |
|
connectionProps); |
212 |
|
logger.info("Connected to database"); |
213 |
|
return conn; |
214 |
|
} |
215 |
|
|
216 |
} |
} |