我有以下代码.我不确定如何安排它们,以便它可以在将记录添加到SQL数据库之前检查CSV中的条目.问题是我仍然在sql中添加双重记录
try {
br = new BufferedReader(new FileReader(file));
String[] data1 = br.readLine().split(cvsSplitBy);
while ((line = br.readLine()) != null) {
String queryCheck = "SELECT Count(Name) from DB WHERE Name = ?";
PreparedStatement st = conn.prepareStatement(queryCheck);
//value is the data of the name column in the CSV
st.setString(1, data1[0]);
ResultSet rs = st.executeQuery();
boolean recordFound = rs.next();
if (recordFound) {
//dont add record
System.out.println("found " + data1[0]);
} else {
String[] data = line.split(cvsSplitBy);
String sql2 = "INSERT INTO DB (Name, ID, …Run Code Online (Sandbox Code Playgroud)