ResultSet videoFilenames 应该有 4162 行(我在数据库中测试了查询),但是 while 循环“while (videoFilenames.next())”只迭代一次 - 在 ResultSet 中的第一个文件名之后,while 循环刚刚结束!谁能帮我弄清楚为什么?
/*
* Run: java -cp .:ojdbc6.jar FindVideosWithoutTranscodes
*/
import java.io.*;
import java.sql.*;
public class FindVideosWithoutTranscodes {
public static void main(String[] args) throws Exception {
//connect to database
Class.forName("oracle.jdbc.OracleDriver");
String serverName = "***.***.***.***";
String portNumber = "****";
String sid = "*****";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
String username = "*****";
String password = "*****";
Connection conn = DriverManager.getConnection(url, username, password);
Statement stmt = conn.createStatement();
//create output file
BufferedWriter out = new BufferedWriter(new FileWriter("mp2_files_without_transcodes.txt"));
//get ResultSet of mp2 filenames
ResultSet videoFilenames = stmt.executeQuery("select filename from archivefile where filename like '%.mp2'");
System.out.println("Making list of mp2 files without transcodes...");
//for each mp2 file
String filename;
ResultSet smallTranscode;
ResultSet largeTranscode;
while (videoFilenames.next()) {
filename = videoFilenames.getString(1);
//check for -700.mov file
System.out.println(filename.substring(0, filename.length() - 4) + "-700.mov"); //test
smallTranscode = stmt.executeQuery("select * from archivefile where filename='" + filename.substring(0, filename.length() - 4) + "-700.mov'");
if (!smallTranscode.next())
out.write(filename + "\n");
else {
//check for -6500.mov file
System.out.println(filename.substring(0, filename.length() - 4) + "-6500.mov"); //test
largeTranscode = stmt.executeQuery("select * from archivefile where filename='" + filename.substring(0, filename.length() - 4) + "-6500.mov'");
if (!largeTranscode.next())
out.write(filename + "\n");
largeTranscode.close();
}
smallTranscode.close();
}
System.out.println("Done.");
out.close();
videoFilenames.close();
}
}