Advertisement
Guest User

Untitled

a guest
Dec 24th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. Connection conn = SqlConnection.getConnection("jdbc:mysql://localhost:3306/stocks");
  2. Statement statement = conn.createStatement();
  3.  
  4. File path = new File("/Users/Zack/Desktop/JavaDB/BALANCESHEETS");
  5. for(File file: path.listFiles()) {
  6. if (file.isFile()) {
  7. String fileName = file.getName();
  8. String ticker = fileName.split("\_")[0];
  9. if (ticker.equals("ASB") || ticker.equals("FRC")) {
  10. if (ticker.equals("ASB")) {
  11. ticker = ticker + "PRD";
  12. }
  13. if (ticker.equals("FRC")) {
  14. ticker = ticker + "PRD";
  15. }
  16. }
  17.  
  18. //CSVReader reader = new CSVReader(new FileReader(file));
  19. //List entries = reader.readAll();
  20. //ArrayList<String> entry = new ArrayList<String>();
  21.  
  22. Reader reader = new BufferedReader(new FileReader(file));
  23. StringBuilder builder = new StringBuilder();
  24.  
  25. int c;
  26. while ((c = reader.read()) != -1) {
  27. builder.append((char) c);
  28. }
  29.  
  30. String string = builder.toString();
  31.  
  32. ArrayList<String> stringResult = new ArrayList<String>();
  33.  
  34. if (string != null) {
  35. String[] splitData = string.split("\s*,\s*|\n");
  36. for (int i = 0; i <splitData.length; i++) {
  37. if (!(splitData[i] == null) || !(splitData[i].length() ==0)) {
  38. stringResult.add(splitData[i].trim());
  39. }
  40. }
  41. }
  42.  
  43. String columnName = null;
  44. int yearCount = 0;
  45. for (int i = 0; i < stringResult.size(); i++) {
  46. int sL = stringResult.get(i).length();
  47.  
  48.  
  49. for (int x = 0; x < sL; x++) {
  50. if (Character.isLetter(stringResult.get(i).charAt(x))) {
  51. yearCount = 0;
  52. System.out.println("index: " + i);
  53. columnName = stringResult.get(i);
  54. columnName = columnName.replace(" ", "_");
  55. System.out.println(columnName);
  56.  
  57. i++;
  58. break;
  59. }
  60. }
  61. yearCount++;
  62. String value = stringResult.get(i);
  63. System.out.println("Year: " + stringResult.get(yearCount) + " Value: " + value + " Stock: " + ticker + " Column: " + columnName );
  64. if (!(columnName == null)) {
  65. String writeValues = "INSERT INTO BalanceSheet (ticker, Year, " + columnName + ") "
  66. + "VALUE ('" + ticker + "','" + stringResult.get(yearCount) + "','" + value + "')";
  67. String writeValues2 = "UPDATE BalanceSheet "
  68. + "SET ticker = '" + ticker + "', "
  69. + "Year = '" + stringResult.get(yearCount) + "', "
  70. + columnName + " = '" + value + "' "
  71. + "WHERE ticker = '" + ticker + "'";
  72. statement.executeUpdate(writeValues2);
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement