Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection conn = SqlConnection.getConnection("jdbc:mysql://localhost:3306/stocks");
- Statement statement = conn.createStatement();
- File path = new File("/Users/Zack/Desktop/JavaDB/BALANCESHEETS");
- for(File file: path.listFiles()) {
- if (file.isFile()) {
- String fileName = file.getName();
- String ticker = fileName.split("\_")[0];
- if (ticker.equals("ASB") || ticker.equals("FRC")) {
- if (ticker.equals("ASB")) {
- ticker = ticker + "PRD";
- }
- if (ticker.equals("FRC")) {
- ticker = ticker + "PRD";
- }
- }
- //CSVReader reader = new CSVReader(new FileReader(file));
- //List entries = reader.readAll();
- //ArrayList<String> entry = new ArrayList<String>();
- Reader reader = new BufferedReader(new FileReader(file));
- StringBuilder builder = new StringBuilder();
- int c;
- while ((c = reader.read()) != -1) {
- builder.append((char) c);
- }
- String string = builder.toString();
- ArrayList<String> stringResult = new ArrayList<String>();
- if (string != null) {
- String[] splitData = string.split("\s*,\s*|\n");
- for (int i = 0; i <splitData.length; i++) {
- if (!(splitData[i] == null) || !(splitData[i].length() ==0)) {
- stringResult.add(splitData[i].trim());
- }
- }
- }
- String columnName = null;
- int yearCount = 0;
- for (int i = 0; i < stringResult.size(); i++) {
- int sL = stringResult.get(i).length();
- for (int x = 0; x < sL; x++) {
- if (Character.isLetter(stringResult.get(i).charAt(x))) {
- yearCount = 0;
- System.out.println("index: " + i);
- columnName = stringResult.get(i);
- columnName = columnName.replace(" ", "_");
- System.out.println(columnName);
- i++;
- break;
- }
- }
- yearCount++;
- String value = stringResult.get(i);
- System.out.println("Year: " + stringResult.get(yearCount) + " Value: " + value + " Stock: " + ticker + " Column: " + columnName );
- if (!(columnName == null)) {
- String writeValues = "INSERT INTO BalanceSheet (ticker, Year, " + columnName + ") "
- + "VALUE ('" + ticker + "','" + stringResult.get(yearCount) + "','" + value + "')";
- String writeValues2 = "UPDATE BalanceSheet "
- + "SET ticker = '" + ticker + "', "
- + "Year = '" + stringResult.get(yearCount) + "', "
- + columnName + " = '" + value + "' "
- + "WHERE ticker = '" + ticker + "'";
- statement.executeUpdate(writeValues2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement