/[projects]/dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Database.java
ViewVC logotype

Diff of /dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/Database.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2146 by torben, Wed Apr 30 08:15:48 2014 UTC revision 2147 by torben, Wed Apr 30 12:53:01 2014 UTC
# Line 1  Line 1 
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;
# Line 16  public class Database { Line 19  public class Database {
19                    
20                    
21          Connection conn;          Connection conn;
22            Connection writeConn;
23            
24          PreparedStatement saveStmt;          PreparedStatement saveStmt;
25    
26          public Database(Connection conn)  throws SQLException {          public Database(Properties conf)  throws SQLException,IOException {
27                  this.conn = conn;                                                conn = getConnection(conf);
28                    writeConn = getConnection(conf);
29                    
30                                    
31                  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`) "+
32                  "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )";                  "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, now() )";
33    
34                  saveStmt = conn.prepareStatement(sql);                            saveStmt = writeConn.prepareStatement(sql);            
35                                    
36          }          }
37                    
38            public void resetResultTable() throws SQLException {
39                    logger.info("Truncating result table");
40                    String sql = "TRUNCATE TABLE fulddaekning.afstand_anden_rute_thn";
41                    writeConn.createStatement().executeUpdate(sql);
42                    
43            }
44            
45            public Connection getConnection(Properties conf) throws SQLException, IOException {
46                    
47                    String db_host = conf.getProperty("DB_HOST");
48                    String db_user = conf.getProperty("DB_USER");
49                    String db_pass = conf.getProperty("DB_PASS");
50    
51                    
52                    
53    
54                Connection conn = null;
55                Properties connectionProps = new Properties();
56                connectionProps.put("user", db_user);
57                connectionProps.put("password", db_pass);
58    
59                    conn = DriverManager.getConnection(
60                               "jdbc:mysql://" +
61                               db_host +
62                               ":3306/",
63                               connectionProps);
64                logger.info("Connected to database");
65                return conn;
66            }
67            
68          public BoundingBox getBoundingbox(int postnr) throws SQLException {          public BoundingBox getBoundingbox(int postnr) throws SQLException {
69                                    
70                  String sql =                  String sql =

Legend:
Removed from v.2146  
changed lines
  Added in v.2147

  ViewVC Help
Powered by ViewVC 1.1.20