Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

records missing when dealing with resultset and string array

Status
Not open for further replies.

chrislee8

Programmer
Aug 21, 2001
5
US
here is the code that has error:

public synchronized String[][] getAllProjectB(String office)
{
Vector rows = new Vector();
command = String.valueOf("select * from project");
try
{
con = dc.getConnect();
stmt = con.createStatement();
results.setFetchSize(8000);
for(results = stmt.executeQuery(command); results.next();
rows.addElement(new Integer(results.getInt(16))))
{
rows.addElement(results.getString(2));
rows.addElement(results.getString(3));
rows.addElement(results.getString(4));
rows.addElement(results.getString(5));
rows.addElement(results.getString(6));
rows.addElement(results.getString(7));
rows.addElement(results.getString(8));
rows.addElement(results.getString(9));
rows.addElement(results.getString(10));
rows.addElement(new Integer(results.getInt(11)));
rows.addElement(new Integer(results.getInt(12)));
rows.addElement(new Integer(results.getInt(13)));
rows.addElement(new Integer(results.getInt(14)));
rows.addElement(new Integer(results.getInt(15)));
}

stmt.close();
dc.closeConnect();
}
catch(SQLException e)
{
System.out.println("sproject--getAllProjectB Failed!");
e.printStackTrace();
}
int len = rows.size() / 15;
String pString[][] = new String[len][15];
int mark = 0;
for(int row = 0; row < len; row++)
{
pString[row][0] =
((String)rows.elementAt(mark++)).replace('^', '\'');
pString[row][1] = (String)rows.elementAt(mark++);
pString[row][2] =
((String)rows.elementAt(mark++)).replace('^', '\'');
pString[row][3] = (String)rows.elementAt(mark++);
pString[row][4] =
((String)rows.elementAt(mark++)).replace('^', '\'');
pString[row][5] = (String)rows.elementAt(mark++);
pString[row][6] = (String)rows.elementAt(mark++);
pString[row][7] = (String)rows.elementAt(mark++);
pString[row][8] = (String)rows.elementAt(mark++);
pString[row][9] =
((Integer)rows.elementAt(mark++)).toString();
pString[row][10] =
((Integer)rows.elementAt(mark++)).toString();
pString[row][11] =
((Integer)rows.elementAt(mark++)).toString();
pString[row][12] =
((Integer)rows.elementAt(mark++)).toString();
pString[row][13] =
((Integer)rows.elementAt(mark++)).toString();
pString[row][14] =
((Integer)rows.elementAt(mark++)).toString();
}

return pString;
}


you can see there are many fields as returning result.
It gave me only 5 records in total in return.


here is the code it works but with LESS fields request:

public synchronized String[][] getAllProjectB(String office)
{
Vector rows = new Vector();
command = String.valueOf(&quot;select * from project&quot;);
try
{
con = dc.getConnect();
stmt = con.createStatement();
//results.setFetchSize(8000);
for(results = stmt.executeQuery(command); results.next();
rows.addElement(results.getString(8)))
{
rows.addElement(results.getString(2));
rows.addElement(results.getString(3));
rows.addElement(results.getString(4));
rows.addElement(results.getString(5));
rows.addElement(results.getString(6));
rows.addElement(results.getString(7));
}

stmt.close();
dc.closeConnect();
}
catch(SQLException e)
{
System.out.println(&quot;sproject--getAllProjectB Failed!&quot;);
e.printStackTrace();
}
int len = rows.size() / 7;
String pString[][] = new String[len][7];
int mark = 0;
for(int row = 0; row < len; row++)
{
pString[row][0] =
((String)rows.elementAt(mark++)).replace('^', '\'');
pString[row][1] = (String)rows.elementAt(mark++);
pString[row][2] =
((String)rows.elementAt(mark++)).replace('^', '\'');
pString[row][3] = (String)rows.elementAt(mark++);
pString[row][4] =
((String)rows.elementAt(mark++)).replace('^', '\'');
pString[row][5] = (String)rows.elementAt(mark++);
pString[row][6] = (String)rows.elementAt(mark++);
}

return pString;
}


It gave me all 118 records in return.

as you can see, with less fields(half in this case) I am able to pull
all data and return them as string array.


how come? what is wrong in the code that cut the records off?

Thanks
 
It looks like you are doing the following:

1.place data from a resultset into a Vector
2.pull elements out of vector and build string
3.return string of concatented results

For the following elements:

rows.addElement(new Integer(results.getInt(11)));
rows.addElement(new Integer(results.getInt(12)));
rows.addElement(new Integer(results.getInt(13)));
rows.addElement(new Integer(results.getInt(14)));
rows.addElement(new Integer(results.getInt(15)));

Could you not treat them like Strings like you did for the first 10 elements of your vector and just drop all of the converting to Integer. I am not sure if this is the right answer, but it is definetly worth a try, espesially if you are not going to do anything with the Integer object. I am fairly certain that you can indeed pull numbers out of a resutset with the getString() method.

 
thanks first

it is working even I only add the 11-15 part to the elements.

So I am more concern about the size of the data passing, i don't know in which part it is extracting or parsing the data wrong. the record.setFetchSize isn't changing anything. but is it the right way to use setFetchSize?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top