i doing text file bulk upload in sql server. whenever tries upload files, gets following exception:
[microsoft] [odbc sql server driver] [sql server]could not bulk insert because file 'c:/form/input_file/form.txt' not opened. operating system error code 3(the system cannot find path specified).
please find below code:
public void uploadfiles() { file dir = new file(inputfilespath); string[] children = dir.list(); string completepathfilename = ""; system.out.println(" inside upload ::"); string savefilenames = ""; preparedstatement prepstat; dbconnection dbconnection=new dbconnection(); connection conhandler= dbconnection.getconnection(); if(null!=conhandler) system.out.println(" clear ::"+conhandler); try { if (children != null) { (int = 0; < children.length; i++) { string filename = children[i]; system.out.println(" children[i]::"+children[i]); // file validated based on business rules. if (isvalidfile(filename) == 1) { string[] filesplit = filename.split("e"); string[] extnsplit = filesplit[1].trim().split(".txt"); completepathfilename += (completepathfilename.equals("")) ? extnsplit[0] : "^" + extnsplit[0]; savefilenames += (savefilenames.equals("")) ? filename : "," + filename; system.out.println(extnsplit[0]); } else { invalidfilenames += (invalidfilenames.equals("")) ? filename : ";\n" + filename; } } if (!completepathfilename.trim().equals("")) { system.out.println(completepathfilename); prepstat = conhandler.preparestatement("exec startfileimport ?"); prepstat.setstring(1, completepathfilename); prepstat.execute(); savefilenametodatabase(savefilenames); } } } catch (sqlexception sql) { system.out.println(sql.getmessage()); } }
getting connection object below code:
public connection getconnection() { system.out.println("in side db connection..."); try{ // database connection class.forname("sun.jdbc.odbc.jdbcodbcdriver"); system.out.println("before driver"); conn= drivermanager.getconnection("jdbc:odbc:form26qa","form26","form26"); system.out.println("after driver"); if(conn != null) { system.out.println("connection established..."); }//if else { system.out.println("connection failed..."); }//else }//try catch(exception e) { system.out.println("exception ocurred..."+e); e.printstacktrace(); }//catch return conn; }
explanation: reading files input path , tried filename , file path , uploading file sql server.
application able find input file in specified path. while uploading getting above mentioned exception
please check , suggest me fix issue.
the file needs accessable on server. file path relative server, not pc. also, if trying use share or mapped drive not work. need use unc path.
unc name examples
\\teela\admin$ (to reach c:\winnt) \\teela\admin$\system32 (to reach c:\winnt\system32) \\teela\temp (to reach c:\temp)
Comments
Post a Comment