Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Unhappy Help with vectors changing size

    Hii,the below code is supposed to take contents of text files(5-10 queries written in notepad..each text file contains only one query) from "input" directory(which contains select queries of DBMS)..if there isnt any 'where' condition in the query, it has to take them for further processing...else it should be removed from vector.
    but this code takes only few...and i have to remove from the vector the ones with "where" in the text file.....

    please help me with the code....

    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.net.*;

    public class eg1
    {



    public static void main(String args[])
    {

    Vector vc;
    int i=0;
    String filename=null,temp=null;
    vc=new Vector();
    Enumeration venum=vc.elements();
    Enumeration venum1=vc.elements();

    try
    {

    File folder = new File("Input\\");
    File[] listOfFiles = folder.listFiles();
    for (i = 0; i < listOfFiles.length; i++)
    {
    if (listOfFiles[i].isFile())
    {
    StringBuffer sb=new StringBuffer();
    filename=listOfFiles[i].getName();
    DataInputStream data1=new DataInputStream(new FileInputStream("Input\\"+filename));
    while((temp=data1.readLine())!=null)
    {
    sb.append(temp);
    }
    String qtemp=sb.toString();
    vc.addElement(qtemp); // to show what is in original vector
    //vc1.addElement(qtemp); // to perform modification to original vector
    }
    }
    }catch(Exception e1){e1.printStackTrace();}





    int j=0;
    while(venum.hasMoreElements())
    {
    System.out.println(vc.elementAt(j).toString().trim ());
    venum.nextElement();
    j++;
    }

    int iii=0;
    while(venum1.hasMoreElements())

    {
    System.out.println("\n\n");
    System.out.println("ITERATION NO:"+iii);
    String query=vc.elementAt(iii).toString().trim(); // one full select query
    System.out.println("QUERY IS "+query);
    int intIndex = query.indexOf("where");
    venum1.nextElement();

    if(intIndex == -1)
    {
    // this if loop checks for the first query without "where" condition
    String str1= vc.elementAt(iii).toString().trim();
    System.out.println(str1);
    int se=str1.indexOf("from");
    String s1=str1.substring(se+5,(str1.length()-1));
    System.out.print("Table name is :::");
    System.out.println(s1);
    iii++;
    }
    else
    {

    vc.remove(iii);
    }

    }

    }
    }

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    the class Vector, for details look here, has different constructors and one of them is

    public Vector(int initialCapacity,
    int capacityIncrement)

    Constructs an empty vector with the specified initial capacity and capacity increment.

    Parameters:
    initialCapacity - the initial capacity of the vector
    capacityIncrement - the amount by which the capacity is increased when the vector overflows
    Throws:
    IllegalArgumentException - if the specified initial capacity is negative

    now, if you now the size of elements use this size + some percents as buffer.
    Last edited by j2me64; 02-07-2011 at 10:17 AM.

Similar Threads

  1. Changing size of Array
    By ravian in forum New To Java
    Replies: 3
    Last Post: 06-05-2012, 08:17 PM
  2. Changing default Applet Viewer Size?
    By dsym@comcast.net in forum Java Applets
    Replies: 6
    Last Post: 08-27-2010, 06:42 PM
  3. Changing JTableModel does not change JScrollpane size
    By stelzergil in forum New To Java
    Replies: 3
    Last Post: 10-19-2009, 02:14 AM
  4. Changing the stack size
    By saif.hakim in forum New To Java
    Replies: 1
    Last Post: 04-26-2009, 06:58 AM
  5. changing font size
    By diggitydoggz in forum New To Java
    Replies: 1
    Last Post: 12-25-2008, 07:48 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •