我在包含多行的文件中有 csv。如果第一列值没有,则它给出错误并且 m 无法插入数据库。ex 如果行是 :130,1,datafile8.csv, 2007 ,17,List_date 读取 n 插入没有问题,但如果行是:,0,datafile8.csv,Bihar,7,list_Left ,无法读取 n 插入 .how在上面的行中插入null。所以我可以在数据库中插入dis行。
String keyword = "celldescription.csv";
File makefile = new File(keyword);
BufferedReader r2 = new BufferedReader(new FileReader(makefile));
strLine1 = r2.readLine();
System.out.println (strLine1);
String r="0";int r1=0;
while((strLine1=r2.readLine())!=null)
{
System.out.println (strLine1);
StringTokenizer st2 = new StringTokenizer(strLine1, ",");
// Print the content on the console
String cellvalue = st2.nextToken();
String position = st2.nextToken();
String Docid=st2.nextToken();
String Word=st2.nextToken();
String Count=st2.nextToken();
String List_Entry=st2.nextToken();
String tab3="insert into description(cellvalue,position,Docid,Word,Count,List_Entry) values(?,?,?,?,?,?)";
ps = connection.prepareStatement(tab3);
ps.setString (1,cellvalue );
ps.setString (2,position );
ps.setString (3,Docid);
ps.setString (4,Word );
ps.setString (5,Count );
ps.setString (6,List_Entry );
ps.executeUpdate();
}//end of while
r2.close();
System.out.println("Data is inserted");
}//try closed**