Python中文网

一个关于 编程问题的解答网站.

有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java异常:操作系统错误代码3

我正在SQL Server中进行文本文件批量上传。每当我试图上传文件时,都会出现以下异常:

[Microsoft] [ODBC SQL Server Driver] [SQL Server]Could not bulk insert because file 'C:/Form/Input_File/Form.txt' could not be opened. Operating System error code 3(The system cannot find the path specified).

请查找以下代码:

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)
                    {
                        for (int i = 0; i < children.length; i++) 
                        {
                            String filename = children[i];
    System.out.println(" children[i]::"+children[i]);
                            // File is validated based on some 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());
                }
}

正在从以下代码获取连接对象:

public Connection getConnection()
    {
        System.out.println("In side DB Connection...");
      try{
            //  get a 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;
    }

说明: 我正在从输入路径读取文件,试图获取文件名和文件路径,并将文件上载到SQL Server

应用程序能够在指定路径中找到输入文件。上传时,我收到了上述异常

请检查并建议我解决这个问题


共 (1) 个答案

  1. # 1 楼答案

    The file needs to be accessable on the server. The file path is relative to the server, not your PC. Also, if you are trying to use a share or a mapped drive it will not work. You need to use the UNC path.

    UNC名称示例

    \\teela\admin$ (to reach C:\WINNT)
    \\teela\admin$\system32 (to reach C:\WINNT\system32)
    \\teela\temp (to reach C:\temp)