简体   繁体   中英

“Cannot Bulk Load” Error in Netbeans.

I know this is an old error. I looked everywhere but still couldn't find the solution. Stackoverflow is my last resort.

Here is what I am doing. I am trying to import a txt file through java into SQL server 2008.

The code I wrote for doing this task is

 public static void main(String[] args)throws Exception {
    try
    {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection con=DriverManager.getConnection("jdbc:sqlserver://SMS-GIGO-IDEN:1433; datbaseName=Testing","sa","paswword");

    Statement stmt = con.createStatement();
    ResultSet rs= stmt.executeQuery("Bulk INSERT Testing.dbo.Link from '\\SMS-GIGO-IDEN\\fa2\\Benchmark\\Output\\B20.link' with (FIELDTERMINATOR='\t', FIRSTROW=2)");

    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

As you can see I have already shared the folder on which I am storing the file. Also, I am using the Machine name.

Note: To check if the machine name is working I accessed SMS-GIGO-IDEN from another machine's SQL server and Bulk is working fine their. In Short BULK QUERY is working from SQL server of any machine. However, Its not working from net beans.

SMS-GIGO-IDEN is a SQL server database and I am running netbeans from the same server where the database is located.

I am loging into SMS-GIGO-IDEN using Windows Authentication. Since I created a SQL server Connection I am not using Windows Login credentials. I created another one as can be seen in my connection string.

So, Is there any one out there who experienced the same thing?

Thanks.

When you run that query from you code you are running it as SA and the user that is trying to get the file from the network share is the user the SQL process is running as. Likely your are running into a permission issue.

See: BULK INSERT (Transact-SQL)

When executing the BULK INSERT statement by using sqlcmd or osql, from one computer, inserting data into SQL Server on a second computer, and specifying a data_file on third computer by using a UNC path, you may receive a 4861 error. To resolve this error, use SQL Server Authentication and specify a SQL Server login that uses the security profile of the SQL Server process account, or configure Windows to enable security account delegation. For information about how to enable a user account to be trusted for delegation, see Windows Help.

This looks like exactly what your are doing.

It might be easier to use a trusted connection as this statement leads me to believe it will just work (if that user has rights to the file share).

If a SQL Server user is logged in using Windows Authentication, the user can read only the files accessible to the user account, independent of the security profile of the SQL Server process.

See: Can I connect to SQL Server using Windows Authentication from Java EE webapp?

Also: Working with a Connection

 Connection con=DriverManager.getConnection("jdbc:sqlserver://SMS-GIGO-IDEN:1433; database=testing;integratedSecurity=true;");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM