Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Object[][] executeQuery(String query) throws SQLException {
- File Tables=new File("C:\\eclipse-workspace\\lab3");
- File[] files= Tables.listFiles();
- query=remove(query);
- String temp=query.toLowerCase();
- String[] split=temp.split("( )|(\\*)|(\\,)");
- String[] noC = null;
- int c=0,m=0,n = 0,condition2=0,flag=0;
- Object[][] table = null;
- if (!query.contains("*")) {
- int j = 0, s = 0;
- for (int i=0;i<split.length;i++)
- {
- if (split[i].contentEquals(""))
- {
- s++;
- }
- if (split[i].contains("from"))
- {
- j=i+1;
- n= i-1-s;
- break;
- }
- }
- condition2=1;
- noC= new String[n];
- for (int i=0;i<n;i++)
- {
- int k=i+1;
- if (!split[k].contentEquals(""))
- {
- noC[i]=split[k];
- }else
- {
- noC[i]=split[k+1];
- }
- }
- }
- int e=0;
- for (int i=0;i<split.length;i++)
- {
- if (split[i].contains("from"))
- {
- e=i+1;
- }
- }
- for (File f : files)
- {
- String name = f.getName().toLowerCase();
- if(name.contentEquals(split[e]+".xml"))
- {
- DocumentBuilderFactory Factory = DocumentBuilderFactory.newInstance();
- try {
- DocumentBuilder Builder = Factory.newDocumentBuilder();
- Document Doc =Builder.parse(f);
- NodeList Rows = Doc.getElementsByTagName("Row");
- for (int i=0;i<Rows.getLength();i++)
- {
- c=0;
- Node R =Rows.item(i);
- if (R.getNodeType()==Node.ELEMENT_NODE)
- {
- Element Row = (Element) R;
- NodeList Columns = Row.getChildNodes();
- m =Rows.getLength();
- if (condition2==0)
- n =(int) (Columns.getLength()-Math.ceil((double)Columns.getLength()/(double)2));
- if (flag==0) {
- table=new Object[m][n];
- flag=1;
- }
- for (int j=0;j<Columns.getLength();j++)
- {
- Node C =Columns.item(j);
- if (C.getNodeType()==Node.ELEMENT_NODE)
- {
- Element Column = (Element) C;
- if (condition2==1)
- {
- if (find (Column.getTagName(),noC))
- {
- table[i][c] = Column.getTextContent();
- c++;
- }
- }else {
- table[i][c] = Column.getTextContent();
- c++;}
- }
- }
- }
- }
- } catch (ParserConfigurationException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (SAXException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- break;
- }
- }
- return table ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement