Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.06 KB | None | 0 0
  1. import java.io.BufferedOutputStream;
  2. import java.io.BufferedReader;
  3. import java.io.BufferedWriter;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileReader;
  7. import java.io.FileWriter;
  8. import java.io.IOException;
  9. import java.net.MalformedURLException;
  10. import java.sql.Connection;
  11. import java.sql.DriverManager;
  12. import java.sql.SQLException;
  13. import java.sql.Statement;
  14. import java.text.DateFormat;
  15. import java.text.SimpleDateFormat;
  16. import java.util.Date;
  17.  
  18.  
  19. public class historyUpdater {
  20.  
  21.     public static void main(String[] args){
  22.         try {
  23.             Citizen.downloadData(new File("C:/testerepdownload/"));
  24.         } catch (MalformedURLException e1) {
  25.             // TODO Auto-generated catch block
  26.             e1.printStackTrace();
  27.         } catch (IOException e1) {
  28.             // TODO Auto-generated catch block
  29.             e1.printStackTrace();
  30.         }
  31.         BufferedReader in=null;
  32.         File[] f = new File("C:/testerepdownload/").listFiles();
  33.         Connection conn=null;
  34.         Statement stmt =null;
  35.         String test="";
  36.         Citizen cit=null;
  37.         try {
  38.             //conn = DriverManager.getConnection("jdbc:mysql://shellmix.com/laxsnor_sql?" +
  39.             //"user=laxsnor_sql");
  40.             conn = DriverManager.getConnection("jdbc:mysql://localhost/mainerepdb?" +
  41.             "user=root");
  42.             stmt =conn.createStatement();
  43.         } catch (SQLException e) {
  44.             // TODO Auto-generated catch block
  45.             e.printStackTrace();
  46.         }
  47.         try {
  48.             for(int i=0;i<f.length;i++){
  49.                 try{
  50.                     in = new BufferedReader(new FileReader(f[i]));
  51.                 }
  52.                 catch (Exception e){
  53.                     i++;
  54.                     in=new BufferedReader(new FileReader(f[i]));
  55.                 }
  56.                 if(in!=null){
  57.                     try{
  58.                     while(!in.readLine().contains("</citizens>")){
  59.                         //System.out.println("Parsing Begins: "+getSQLDateTime());
  60.                         cit=Citizen.parseFromFile(in);
  61.                         //System.out.println("Parsing Ends: "+getSQLDateTime());
  62.                         if(cit!=null){
  63.                             try{
  64.                                 cit.addToHistoryDb((com.mysql.jdbc.Statement) stmt, "citizenhistory");
  65.                             }
  66.                             catch(com.mysql.jdbc.exceptions.jdbc4.CommunicationsException e){
  67.                                 //conn = DriverManager.getConnection("jdbc:mysql://shellmix.com/laxsnor_sql?" +
  68.                                 //"user=laxsnor_sql");
  69.                                 conn = DriverManager.getConnection("jdbc:mysql://localhost/mainerepdb?" +
  70.                                 "user=root&password");
  71.                                 stmt =conn.createStatement();
  72.                             }
  73.                             catch(com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException e){
  74.  
  75.                             }
  76.                         }
  77.                         else{
  78.                             try{
  79.                                 while(!in.readLine().contains("</citizen>"));
  80.                             }catch(java.lang.NullPointerException e ){
  81.                                 break;
  82.                             }
  83.                         }
  84.                     }
  85.                     }
  86.                     catch(java.lang.NullPointerException e){
  87.                         System.out.println(f[i].getAbsoluteFile());
  88.                     }
  89.                 }
  90.             }
  91.             System.out.println(test);
  92.         //  bw.close();
  93.         } catch (Exception e) {
  94.             // TODO Auto-generated catch block
  95.             e.printStackTrace();
  96.         }
  97.     }
  98.  
  99.     private static String getSQLDateTime() {
  100.         DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  101.         Date date = new Date();
  102.         return dateFormat.format(date).substring(0,10)+"T"+dateFormat.format(date).substring(11);
  103.     }
  104.  
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement