我正在从 .csv 文件导入数据库值。但是,.csv 中的第一行实际上是表列的名称,我的导入程序将其作为第一行更新数据库。这会搞乱我稍后用它做的查询。请帮助我如何防止这种情况?
我的 .csv 导入器的代码
try
{
BufferedReader br=new BufferedReader(new FileReader("v.csv"));
String line;
while((line=br.readLine())!=null)
{
String[]value = line.split(",");
String sql = "INSERT into main ([Ticket #], Status, Priority, Department, [Account Name]) "
+ "values ('"+value[0]+"','"+value[1]+"','"+value[2]+"','"+value[3]+"','"+value[4]+"')";
System.out.println(sql);
PreparedStatement pst = null;
try
{
pst = db.prepareStatement(sql);
pst.executeUpdate();
}finally{
if(pst != null){
pst.close();
}
}
}
br.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
最佳答案
String line;
line=br.readLine(); //read the line and do nothing with the line
while((line=br.readLine())!=null)
{
关于Java - 将 .csv 导入数据库 - 排除第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22344334/