Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. public Object[][] executeQuery(String query) throws SQLException {
  2. File Tables=new File("C:\\eclipse-workspace\\lab3");
  3. File[] files= Tables.listFiles();
  4. query=remove(query);
  5. String temp=query.toLowerCase();
  6. String[] split=temp.split("( )|(\\*)|(\\,)");
  7. String[] noC = null;
  8. int c=0,m=0,n = 0,condition2=0,flag=0;
  9. Object[][] table = null;
  10. if (!query.contains("*")) {
  11.  
  12. int j = 0, s = 0;
  13.  
  14. for (int i=0;i<split.length;i++)
  15. {
  16. if (split[i].contentEquals(""))
  17. {
  18. s++;
  19. }
  20. if (split[i].contains("from"))
  21. {
  22. j=i+1;
  23. n= i-1-s;
  24. break;
  25. }
  26. }
  27.  
  28. condition2=1;
  29.  
  30. noC= new String[n];
  31.  
  32. for (int i=0;i<n;i++)
  33. {
  34. int k=i+1;
  35. if (!split[k].contentEquals(""))
  36. {
  37. noC[i]=split[k];
  38. }else
  39. {
  40. noC[i]=split[k+1];
  41. }
  42.  
  43. }
  44. }
  45. int e=0;
  46. for (int i=0;i<split.length;i++)
  47. {
  48.  
  49. if (split[i].contains("from"))
  50. {
  51. e=i+1;
  52. }
  53.  
  54. }
  55. for (File f : files)
  56. {
  57. String name = f.getName().toLowerCase();
  58. if(name.contentEquals(split[e]+".xml"))
  59. {
  60. DocumentBuilderFactory Factory = DocumentBuilderFactory.newInstance();
  61.  
  62. try {
  63. DocumentBuilder Builder = Factory.newDocumentBuilder();
  64. Document Doc =Builder.parse(f);
  65. NodeList Rows = Doc.getElementsByTagName("Row");
  66. for (int i=0;i<Rows.getLength();i++)
  67. {
  68. c=0;
  69. Node R =Rows.item(i);
  70. if (R.getNodeType()==Node.ELEMENT_NODE)
  71. {
  72. Element Row = (Element) R;
  73. NodeList Columns = Row.getChildNodes();
  74. m =Rows.getLength();
  75. if (condition2==0)
  76. n =(int) (Columns.getLength()-Math.ceil((double)Columns.getLength()/(double)2));
  77. if (flag==0) {
  78. table=new Object[m][n];
  79. flag=1;
  80. }
  81. for (int j=0;j<Columns.getLength();j++)
  82. {
  83. Node C =Columns.item(j);
  84. if (C.getNodeType()==Node.ELEMENT_NODE)
  85. {
  86. Element Column = (Element) C;
  87.  
  88.  
  89. if (condition2==1)
  90. {
  91.  
  92. if (find (Column.getTagName(),noC))
  93. {
  94. table[i][c] = Column.getTextContent();
  95. c++;
  96. }
  97. }else {
  98. table[i][c] = Column.getTextContent();
  99. c++;}
  100.  
  101. }
  102. }
  103. }
  104. }
  105.  
  106.  
  107. } catch (ParserConfigurationException e1) {
  108. // TODO Auto-generated catch block
  109. e1.printStackTrace();
  110. } catch (SAXException e1) {
  111. // TODO Auto-generated catch block
  112. e1.printStackTrace();
  113. } catch (IOException e1) {
  114. // TODO Auto-generated catch block
  115. e1.printStackTrace();
  116. }
  117. break;
  118. }
  119.  
  120. }
  121.  
  122. return table ;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement