Database db2";导出为文件名.csv“;给定IO错误

Database db2";导出为文件名.csv“;给定IO错误,database,csv,db2,export,Database,Csv,Db2,Export,我尝试使用JDBC连接导出数据(我使用的是DB2数据库),但失败并出现以下错误: 由以下原因引起:com.ibm.db2.jcc.c.SqlException:db2sql错误:SQLCODE:-3001,SQLSTATE:,SQLERRMC:sqlofopn-2029060079 我使用的查询: 调用admin_cmd('EXPORT TO/home/user/test_1/db_extract.csv OF DEL 由NOCHARDEL SELECT*从mytable中修改,仅获取前5行'

我尝试使用JDBC连接导出数据(我使用的是DB2数据库),但失败并出现以下错误:

由以下原因引起:com.ibm.db2.jcc.c.SqlException:db2sql错误:SQLCODE:-3001,SQLSTATE:,SQLERRMC:sqlofopn-2029060079

我使用的查询:

调用admin_cmd('EXPORT TO/home/user/test_1/db_extract.csv OF DEL 由NOCHARDEL SELECT*从mytable中修改,仅获取前5行'

我还授予了755访问test_1文件夹的权限。 我也尝试删除admin_cmd,但得到语句开头错误

还使用putty尝试了相同的查询,但我没有遇到以下错误:

SQL3001C发生I/O错误(reason=“sqlofopn-2029060079”) 打开输出文件时


您需要向DB2Fenced用户和/或DB2Fenced用户所属的组授予权限。例如:

-- file /tmp/stack.sql
connect to pocdb user proksch using in4mix;

call admin_cmd('export to /stack/my.unl of del select * from proksch.foo');

connect reset;

terminate;
以下stack.sh脚本作为root用户(或可以动态设置ACL的其他用户)运行

产生以下结果:

Perms on /stack
drwxr-xr-x+   2 unload ops   4096 Mar 22 16:17 stack
# file: /stack
USER   unload    rwx
GROUP  ops       r-x
mask             r-x
other            r-x


connect to pocdb user proksch using

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = PROKSCH
 Local database alias   = POCDB


call admin_cmd('export to /stack/my.unl of del select * from proksch.foo')
SQL3001C  An I/O error (reason = "sqlofopn -2079391743") occurred while
opening the output file.

connect reset
DB20000I  The SQL command completed successfully.

terminate
DB20000I  The TERMINATE command completed successfully.


Perms on /stack
drwxrwxr-x+   2 unload ops   4096 Mar 22 16:17 stack
# file: /stack
USER   unload    rwx
user   db2inst1  rwx
GROUP  ops       r-x
mask             rwx
other            r-x


connect to pocdb user proksch using

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = PROKSCH
 Local database alias   = POCDB


call admin_cmd('export to /stack/my.unl of del select * from proksch.foo')
SQL3001C  An I/O error (reason = "sqlofopn -2079391743") occurred while
opening the output file.

connect reset
DB20000I  The SQL command completed successfully.

terminate
DB20000I  The TERMINATE command completed successfully.


Perms on /stack
drwxrwxr-x+   2 unload ops   4096 Mar 22 16:17 stack
# file: /stack
USER   unload    rwx
user   db2fence  rwx
GROUP  ops       r-x
mask             rwx
other            r-x


connect to pocdb user proksch using

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = PROKSCH
 Local database alias   = POCDB


call admin_cmd('export to /stack/my.unl of del select * from proksch.foo')

  Result set 1
  --------------

  ROWS_EXPORTED        MSG_RETRIEVAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    MSG_REMOVAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                     5 -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

  1 record(s) selected.

  Return Status = 0

connect reset
DB20000I  The SQL command completed successfully.

terminate
DB20000I  The TERMINATE command completed successfully.


Perms on /stack
drwxrwxr-x+   2 unload ops   4096 Mar 22 16:17 stack
# file: /stack
USER   unload    rwx
GROUP  ops       r-x
group  db2       rwx
mask             rwx
other            r-x


connect to pocdb user proksch using

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = PROKSCH
 Local database alias   = POCDB


call admin_cmd('export to /stack/my.unl of del select * from proksch.foo')


  Result set 1
  --------------

  ROWS_EXPORTED        MSG_RETRIEVAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    MSG_REMOVAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                     5 -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

  1 record(s) selected.

  Return Status = 0

connect reset
DB20000I  The SQL command completed successfully.

terminate
DB20000I  The TERMINATE command completed successfully.

在windows中,问题在于路径访问。
以管理员权限运行db2解决了这个问题(通过更改文件路径也可以解决这个问题)。

1。您知道这会将文件写入数据库服务器上的一个目录,对吗?2。该目录必须可由实例的受保护用户写入。755意味着只有目录的所有者才有写权限。我也尝试过给文件夹777,仍然是相同的问题。但是,当我删除admin_cmd时,当我直接从实例运行查询时,它会起作用,但在JDBC连接中不起作用?另外-这是一个通过JDBC或类似DataStudio的东西调用admin\u cmd的自制应用程序吗?@proksch\u ibm我试着用admin\u cmd运行,它给出了错误,但没有admin\u cmd它可以工作。它只是一个简单的Java应用程序。
Perms on /stack
drwxr-xr-x+   2 unload ops   4096 Mar 22 16:17 stack
# file: /stack
USER   unload    rwx
GROUP  ops       r-x
mask             r-x
other            r-x


connect to pocdb user proksch using

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = PROKSCH
 Local database alias   = POCDB


call admin_cmd('export to /stack/my.unl of del select * from proksch.foo')
SQL3001C  An I/O error (reason = "sqlofopn -2079391743") occurred while
opening the output file.

connect reset
DB20000I  The SQL command completed successfully.

terminate
DB20000I  The TERMINATE command completed successfully.


Perms on /stack
drwxrwxr-x+   2 unload ops   4096 Mar 22 16:17 stack
# file: /stack
USER   unload    rwx
user   db2inst1  rwx
GROUP  ops       r-x
mask             rwx
other            r-x


connect to pocdb user proksch using

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = PROKSCH
 Local database alias   = POCDB


call admin_cmd('export to /stack/my.unl of del select * from proksch.foo')
SQL3001C  An I/O error (reason = "sqlofopn -2079391743") occurred while
opening the output file.

connect reset
DB20000I  The SQL command completed successfully.

terminate
DB20000I  The TERMINATE command completed successfully.


Perms on /stack
drwxrwxr-x+   2 unload ops   4096 Mar 22 16:17 stack
# file: /stack
USER   unload    rwx
user   db2fence  rwx
GROUP  ops       r-x
mask             rwx
other            r-x


connect to pocdb user proksch using

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = PROKSCH
 Local database alias   = POCDB


call admin_cmd('export to /stack/my.unl of del select * from proksch.foo')

  Result set 1
  --------------

  ROWS_EXPORTED        MSG_RETRIEVAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    MSG_REMOVAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                     5 -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

  1 record(s) selected.

  Return Status = 0

connect reset
DB20000I  The SQL command completed successfully.

terminate
DB20000I  The TERMINATE command completed successfully.


Perms on /stack
drwxrwxr-x+   2 unload ops   4096 Mar 22 16:17 stack
# file: /stack
USER   unload    rwx
GROUP  ops       r-x
group  db2       rwx
mask             rwx
other            r-x


connect to pocdb user proksch using

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.3
 SQL authorization ID   = PROKSCH
 Local database alias   = POCDB


call admin_cmd('export to /stack/my.unl of del select * from proksch.foo')


  Result set 1
  --------------

  ROWS_EXPORTED        MSG_RETRIEVAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    MSG_REMOVAL                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  -------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                     5 -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                -                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

  1 record(s) selected.

  Return Status = 0

connect reset
DB20000I  The SQL command completed successfully.

terminate
DB20000I  The TERMINATE command completed successfully.