Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. package pkjio;
  2.  
  3. import db.DB;
  4. import java.io.BufferedReader;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import java.io.StringWriter;
  9. import log.ErrorLog;
  10.  
  11. public class TessToCSV {
  12. StringWriter errors = new StringWriter();
  13. public TessToCSV(boolean toDB){
  14. String vOutputFileName = "C://Temp//Javacode//myfile.csv";
  15. String vInputFileName = "C://Temp//Javacode//AirPagssangers.txt";
  16. try {
  17. BufferedReader br = new BufferedReader(new FileReader(vInputFileName));
  18. String data = ",";
  19. int begin = 0;
  20. int end = 3;
  21. String months = br.readLine().toString();
  22. for(int i=0; i<=11; i++){
  23. data += months.substring(begin, end) + ",";
  24. begin = end;
  25. end += 3;
  26. }
  27. new TestWriter2(vOutputFileName, data.toString());
  28.  
  29. data = "";
  30.  
  31. for(String line; (line = br.readLine()) != null; ) {
  32. begin = 0;
  33. end = 4;
  34. String vtoTable = "";
  35. for(int i=0; i<=12; i++){
  36. if(toDB){
  37. vtoTable += "'" + line.substring(begin, end).toString() + "', ";
  38. }
  39. data += line.substring(begin, end) + ",";
  40. begin = end;
  41. end += 3;
  42. }
  43. new TestWriter2(vOutputFileName, data.toString());
  44. data = "";
  45. if(toDB){
  46. doInserData(vtoTable.substring(0, vtoTable.length() -2));
  47. }
  48. }
  49.  
  50. } catch(IOException e){
  51. doPrintLog(e);
  52. }
  53. }
  54.  
  55.  
  56. public void doInserData(String vdata){
  57. DB db = new DB();
  58. String vSQL = "INSERT INTO ap ";
  59. vSQL += "( Year, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, `Dec` ) ";
  60. vSQL += " VALUES ( " + vdata + ")";
  61.  
  62. System.out.println(vSQL);
  63. try {
  64. db.ExcuteSQL(vSQL);
  65. }catch(Exception e){
  66. e.printStackTrace();
  67. } finally{
  68. db.doClose();
  69. }
  70. }
  71. private void doPrintLog(Exception e){
  72. e.printStackTrace(new PrintWriter(errors));
  73. new ErrorLog(errors.toString());
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement