使用 DB2 SYSPROC.ADMIN_CMD 进行数据库导入时出现字符集问题
我正在运行一个 Java 应用程序,它将需要导入的文件传输到 DB2 所在的服务器。然后,Java 应用程序创建到数据库的 JDBC 连接并运行:
CALL SYSPROC.ADMIN_CMD('import from <filename> of del modified by decpt, coldel; messages on server inert into <view>')
我遇到的问题似乎与数据库用于导入文件的用户数据库的字符集(使用 admin_cmd 存储过程)有关。这个问题是: “元音变音”,比如 ä,ö,ü 被这个导入弄乱了。我过去遇到过此类问题,解决方案始终是设置将数据导入到 de_DE.iso88591 的用户的 LC_CTYPE
我已经排除了问题的根源: - 将文件传输到数据库服务器。 (元音变音之后仍然可以) - JDBC 连接(我只是通过 sql 命令插入一行而不是从文件中读取)
问题是我现在不知道 DB2 使用什么用户通过 ADMIN_CMD 导入文件。而且我也不相信它可以以某种方式连接到 DB2 设置,因为使用所有其他方式插入、加载……数据到其中,一切都工作正常。
是的,我需要使用 ADMIN_CMD。 DB2 命令行工具是性能噩梦......
I am running a Java Application that transfers the files I need to import to the server the DB2 is on. Then the Java Application creates a JDBC Connection to the database and runs:
CALL SYSPROC.ADMIN_CMD('import from <filename> of del modified by decpt, coldel; messages on server inert into <view>')
The problem I have seems somehow conencted to the charset of either the database of the user the database uses to import the files (using the admin_cmd stored procedure). That problem is:
"Umlaute", like ä,ö,ü get messed up by this import. I had this sort of problem in the past and solution always was to set the LC_CTYPE of the user importing the data to de_DE.iso88591
What I already ruled out as the source of the problem:
- The file transfer to the database server. (Umlaute are still ok after that)
- The JDBC Connection (I simply inserted a line through the sql command instead of reading from a file)
The thing is I don't now what user DB2 uses to import files through ADMIN_CMD. And I also don't believe it could somehow be connected to the DB2 settings, since with every other way of inserting,loading ... data into it, everthing works fine.
And yes, I need to use ADMIN_CMD. The DB2 Command Line Tool is a performance nightmare ..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好的方法(为了理智):
DB2 确实尝试变得聪明并将输入数据转换为你(导入命令基本上将你的数据传输到插入子句中 - 总是像这样处理)。我给出的链接将概述基本原理,并为您提供一些可以尝试的命令。另外,还有官方解释类似。根据它,您可以尝试设置环境变量 db2codepage 以与您的分隔数据文件相对应,这应该会有所帮助。此外,IXF 格式导出可能会更好,因为它们在每个文件中附加了与编码相关的信息。
The best approach (for sanity):
DB2 indeed attempts to be smart and convert your input data for you (the import command basically pipes your data into insert clauses - which always get handled like that). The link I gave will outline the basic principle, and give you a few commands to try out. Also, there is official explanation to the similar. According it you could attempt setting the environment variable db2codepage to correspond with your delimited data files, and that should help. Also, the IXF format exports might work better since they have encoding related information attached in every file.
感谢您的回复。
添加一个 ADMIN_CMD 导入命令解决了该问题
我最终通过向 JDBC 。这似乎覆盖了数据库之前使用的任何代码页设置。数据库的默认代码页似乎也并不重要,因为它设置为 1252。我现在唯一能想到的导致这一切的原因可能是 DB2 在通过 ADMIN_CMD 导入时使用的 Linux 设置。
Thanks for your response.
I finally fixed the issue by adding a
to my JDBC - ADMIN_CMD Import Command. This seems to override any codepage settings the db was using before. It also appears the default codepage of the database didn't matter, since it is set to 1252. The only thing I can think of right now for being the reason for all this could be a linux setting DB2 uses when importing through ADMIN_CMD.