Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedOutputStream;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- public class historyUpdater {
- public static void main(String[] args){
- try {
- Citizen.downloadData(new File("C:/testerepdownload/"));
- } catch (MalformedURLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- BufferedReader in=null;
- File[] f = new File("C:/testerepdownload/").listFiles();
- Connection conn=null;
- Statement stmt =null;
- String test="";
- Citizen cit=null;
- try {
- //conn = DriverManager.getConnection("jdbc:mysql://shellmix.com/laxsnor_sql?" +
- //"user=laxsnor_sql");
- conn = DriverManager.getConnection("jdbc:mysql://localhost/mainerepdb?" +
- "user=root");
- stmt =conn.createStatement();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- for(int i=0;i<f.length;i++){
- try{
- in = new BufferedReader(new FileReader(f[i]));
- }
- catch (Exception e){
- i++;
- in=new BufferedReader(new FileReader(f[i]));
- }
- if(in!=null){
- try{
- while(!in.readLine().contains("</citizens>")){
- //System.out.println("Parsing Begins: "+getSQLDateTime());
- cit=Citizen.parseFromFile(in);
- //System.out.println("Parsing Ends: "+getSQLDateTime());
- if(cit!=null){
- try{
- cit.addToHistoryDb((com.mysql.jdbc.Statement) stmt, "citizenhistory");
- }
- catch(com.mysql.jdbc.exceptions.jdbc4.CommunicationsException e){
- //conn = DriverManager.getConnection("jdbc:mysql://shellmix.com/laxsnor_sql?" +
- //"user=laxsnor_sql");
- conn = DriverManager.getConnection("jdbc:mysql://localhost/mainerepdb?" +
- "user=root&password");
- stmt =conn.createStatement();
- }
- catch(com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException e){
- }
- }
- else{
- try{
- while(!in.readLine().contains("</citizen>"));
- }catch(java.lang.NullPointerException e ){
- break;
- }
- }
- }
- }
- catch(java.lang.NullPointerException e){
- System.out.println(f[i].getAbsoluteFile());
- }
- }
- }
- System.out.println(test);
- // bw.close();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- private static String getSQLDateTime() {
- DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date = new Date();
- return dateFormat.format(date).substring(0,10)+"T"+dateFormat.format(date).substring(11);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement