Missing output

P

pk

I'm having trouble working out the logic of this error. I've got a
file of 12881 lines. I read it in and compare it line by line to a
query that i've returned. If it matches it goes to output A, if not,
output B. For some reason, I'm only getting 12230 lines accounted for
(A + B). Is there somewhere in my code that I should be closing to
flush out the buffers? I suppose this could all be a product of some
of the sloppiest code ever, but I'd appreciate if someone could verify
that too.

Here's the code: (i sincerely apologize for the ugliness, it's
embarrassing)

----------------------------------------------
import java.io.*;
import java.sql.*;

public class bulkInsertCreator {
public static void main(String[] args) {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

String url =
"jdbc:Microsoft:sqlserver://hal:1433;DatabaseName=Test";
Connection conn =
DriverManager.getConnection(url,"thisis","fake");

Statement stmt = conn.createStatement();
BufferedReader brdr = new BufferedReader(new
FileReader("NonBreakPoint.txt"));
String query = "select IV00105.LISTPRCE, IV00105.ITEMNMBR from
IV00105 where LISTPRCE != 0 order by ITEMNMBR";
ResultSet rs = stmt.executeQuery(query);
String[] listPrice, itemNmbr;
listPrice = new String[20000];
itemNmbr = new String[20000];
int i = 0;
while (rs.next()){
listPrice = rs.getString("LISTPRCE");
itemNmbr = rs.getString("ITEMNMBR");
i++;
}
rs.close();
String temp = brdr.readLine();
int counter = 0;
PrintWriter out = new PrintWriter(new
FileOutputStream("Unmatched.txt"));
boolean matched;
for (int j = 0; j<i; j++) {
matched = false;
for (int k = 0; k<i; k++) {
if(itemNmbr[k].equals(temp)) {
System.out.println("NET\tI\t" + itemNmbr[k].trim() +
"\tEACH\t1\t999999999999\t" + listPrice[k] + "\t1\t1\t16384");
counter++;
matched = true;
}
}
if(matched != true) {
out.println("No match for " + temp + ".");
}
temp = brdr.readLine();
}
out.close();
System.out.println(counter + " rows.");
//System.out.println(query);
} catch (Exception e) {
System.out.println(e);
}
}
}
-----------------------------------------------------

Thanks. I appreciate those of you who are donating your brain power to
this. :)

-pk
 
J

jerry

temp=brdr.readLine(); is inside the "J" loop. Take it outside the loop
and check for EOF instead.
 
P

pk

The temp=brdr.readLine(); was supposed to be inside the "J" loop, but
you were right about the EOF condition. That seemed to do the trick
when I changed the "J" loop to a while loop checking for the
nullability of temp.

Thanks again.

-pk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top