1. Download the Dbfreader jar package
2. Instance Code
PackageService;ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;ImportJava.io.InputStream;Importjava.io.UnsupportedEncodingException;Importjava.sql.Connection;Importjava.sql.PreparedStatement;Importjava.sql.SQLException;ImportJava.util.HashSet;ImportJava.util.Set;Importutil. Dbutil;Importcom.linuxense.javadbf.DBFException;ImportCom.linuxense.javadbf.DBFReader; Public classdbfutil{Private Static FinalString insertsql = "INSERT into V_SSMZ (Ye,no,dp,e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15,e16,e17,e18, E19) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; Private Static FinalString updatesql = "Update v_ssmz set ye=?,no=?,dp=?,e0=?,e1=?,e2=?,e3=?,e4=?,e5=?,e6=?,e7=?,e8=?,e9=?,e10=?,e11=?" E12=?,e13=?,e14=?,e15=?,e16=?,e17=?,e18=?,e19=? where ye =? and no=? "; Public Static voidMain (string[] args) {dbfutil SDF=NewDbfutil (); Try{sdf. Dbfreader ("V_ssmz", "d:\\ common software \\jar package \\ssbase. DBF "); }Catch(SQLException e) {e.printstacktrace (); } } Public voidDbfreader (String tablename,string FilePath)throwssqlexception{Set<String> map =NewHashSet <String> (); Dbfreader Reader=NULL;//get content from DBFConnection con =NULL; PreparedStatement Insertstat=NULL; PreparedStatement Updatestat=NULL; InputStream in; Try{ in=NewFileInputStream (NewFile (FilePath)); Reader=NewDbfreader (in);//reads the file from the file stream. object[] Rowobjects=NULL; Con=dbutil.getplantdbconnection (); Insertstat=con.preparestatement (Insertsql); Updatestat=con.preparestatement (Updatesql); while((rowobjects = Reader.nextrecord ())! =NULL) {String ye=NewString (rowobjects[0].tostring (). Trim (). GetBytes ("Iso-8859-1"), "GBK"); String No=NewString (rowobjects[1].tostring (). Trim (). GetBytes ("Iso-8859-1"), "GBK"); if(Map.contains (ye+ "_" +no)) { for(inti=0;i<rowobjects.length;i++) {String value= rowobjects[i]==NULL?"":NewString (rowobjects[i].tostring (). Trim (). GetBytes ("Iso-8859-1"), "GBK"); Updatestat.setstring (i+1, value); } updatestat.setstring (Rowobjects.length+1,NewString (rowobjects[0].tostring (). Trim (). GetBytes ("Iso-8859-1"), "GBK")); Updatestat.setstring (Rowobjects.length+2,NewString (rowobjects[1].tostring (). Trim (). GetBytes ("Iso-8859-1"), "GBK")); Updatestat.addbatch (); }Else{ for(inti=0;i<rowobjects.length;i++) {String value= rowobjects[i]==NULL?"":NewString (rowobjects[i].tostring (). Trim (). GetBytes ("Iso-8859-1"), "GBK"); Insertstat.setstring (i+1, value); } insertstat.addbatch (); } map.add (Ye+"_"+no); } insertstat.executebatch (); Updatestat.executebatch (); }Catch(FileNotFoundException e) {e.printstacktrace (); }Catch(dbfexception e) {e.printstacktrace (); }Catch(SQLException e) {e.printstacktrace (); }Catch(unsupportedencodingexception e) {e.printstacktrace (); }finally{updatestat.close (); Updatestat.close (); Con.close (); } }}
Java Read DBF file