Results 1 to 2 of 2
Thread: Help with vectors changing size
- 02-07-2011, 09:53 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 2
- Rep Power
- 0
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);
}
}
}
}
- 02-07-2011, 10:13 AM #2
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
-
Changing size of Array
By ravian in forum New To JavaReplies: 3Last Post: 06-05-2012, 08:17 PM -
Changing default Applet Viewer Size?
By dsym@comcast.net in forum Java AppletsReplies: 6Last Post: 08-27-2010, 06:42 PM -
Changing JTableModel does not change JScrollpane size
By stelzergil in forum New To JavaReplies: 3Last Post: 10-19-2009, 02:14 AM -
Changing the stack size
By saif.hakim in forum New To JavaReplies: 1Last Post: 04-26-2009, 06:58 AM -
changing font size
By diggitydoggz in forum New To JavaReplies: 1Last Post: 12-25-2008, 07:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks