You are trying to compare one file with all the assignment files whose locations are stored in database. First thing to me is that there will be memory leak due to not closed buffered reader. Please correct this first. I will look deeper to your algorithm. thanks.
--- Update ---
You'd better split your code into different functional levels. for instance:
public void compareFiles(String file2){
int lineSimilar2 = 0;
try{
origBR = new BufferedReader(new FileReader(file));
int doc = 0;
int y = 0;
String line = "";
String line2 = "";
while((line = origBR.readLine()) != null){
BufferedReader br2 = new BufferedReader(new FileReader(file2));
while((line2 = br2.readLine()) != null){
if(line.equals(line2)){
y++;
doc++;
lineSimilar++;
lineSimilar2++;
}
else
lineNotSimilar++;
}
}
System.out.println(lineSimilar + " lines are similar");
System.out.println(lineNotSimilar + " lines are not similar");
}catch(Exception e){
e.printStackTrace();
}
}
public void compare(){
//read in files from database
//loop each file from resultset and compare with the original file
compareFiles(eachFile);
Alternatively, because you are only reading files and compare them, you may use multiple threads to compare multiple files at the same time