我有以下问题。 我有一个GUI,用户可以上传一些csv文件和这个文件存储在我的数据库中。同时,如果作为上载文件中第一列的ID也存储在我的数据库表中,则检查该文件,该数据库表包含大约700.000条记录。所以我想将上传文件中的任何一行与我的数据库ID列进行比较。现在我进行测试,从我的数据库中导出表并缩小它们,仅用于测试。但是如果我上传这个文件并想要比较,它就不会打任何ID - 虽然它是同一个文件,只是更小。
这是我的代码:
String line = null;
out = new BufferedWriter(new FileWriter("C:\\auditUp\\gef.txt"));
EntityManager emt = emf.createEntityManager();
EntityTransaction transcation = emt.getTransaction();
int i = 0;
while ((line = reader.readLine()) != null)
{
i++;
String[] content = line.split(";");
if(content.length < 2)
{
System.out.println("Ende");
out.flush();
out.close();
reader.close();
return;
}
transcation.begin();
TypedQuery<Datensatz> q = emt.createQuery("SELECT d FROM Datensatz d WHERE d.Id = :Id",Datensatz.class);
q.setParameter("Id", content[0]);
List<Datensatz> gefunden = q.getResultList();
transcation.commit();
if(!gefunden.isEmpty())
{
System.out.println(i);
out.write(i + ": " + gefunden);
out.newLine();
}
else
{
System.out.println("Liste ist leer");
}
}
emt.close();
reader.close();
}catch(Exception e)
{
e.printStackTrace();
}
finally{
fis.close();
if(out != null)
{
try {
out.flush();
out.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
我的实体类看起来像这样:
@Entity
public class Datensatz implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private String Id;
private String Relative_ID;
private String Title;
private String Gender;
private String First_Name;
private String Last_Name;
private String Full_Name;
private String Other_Names;
private String Alternative_Script;
private String Function;
private String Category;
private String DOB;
private String POB;
private String Country;
private String Code;
private String Additional_Information;
private String Country_Of_Origin;
private String Country_Of_Activity;
[getter and setter]
}