Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. public void saveNozzleMeasureToDB (){
  2.         final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
  3.         final String DB_URL = "jdbc:mysql://localhost:6033/";
  4.         //  Database credentials
  5.         final String USER = "root";
  6.         final String PASS = "";
  7.         Connection conn = null;
  8.         Statement stmt = null;
  9.         try{
  10.            Class.forName("com.mysql.jdbc.Driver");
  11.            conn = DriverManager.getConnection(DB_URL, USER, PASS);
  12.            stmt = conn.createStatement();
  13.            String sql = "Use station";      
  14.            stmt.executeUpdate(sql);
  15.            stmt = conn.createStatement();
  16.            while (this.nozzleMeasuresBufferSize > 0){
  17.                 sql = "Insert into nozzlemeasures Values('" + DATE_FORMAT.format(DATE_FORMAT.parse(nozzleMeasuresList.get(0).data)) + "', " + nozzleMeasuresList.get(0).nozzleID + ", " + nozzleMeasuresList.get(0).tankID + ", " + 0 +
  18.                         ", " + nozzleMeasuresList.get(0).literCounter + ", " + nozzleMeasuresList.get(0).totalCounter + ", " + nozzleMeasuresList.get(0).status +  ");";      
  19.                 stmt.executeUpdate(sql);
  20.                 this.nozzleMeasuresList.remove(0);
  21.                 this.nozzleMeasuresBufferSize--;
  22.            }
  23.         }catch(SQLException se){
  24.            se.printStackTrace();
  25.         }catch(Exception e){
  26.            e.printStackTrace();
  27.         }finally{
  28.            try{
  29.               if(stmt!=null)
  30.                  stmt.close();
  31.            }catch(SQLException se2){
  32.            }
  33.            try{
  34.               if(conn!=null)
  35.                  conn.close();
  36.            }catch(SQLException se){
  37.               se.printStackTrace();
  38.            }
  39.         }      
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement