使用JDBC连接DB2时,发生错误:
com.ibm.db2.jcc.b.DisconnectException: encoding not supported!!
......
上网查了很久发现是DB2的编码本地的Java环境不支持(数据库代码页使用的是GBK的编码)
总结一下,共有2种解决办法:
1. 使用IBM JRE运行应用。
2. 使用UTF-8代码页创建数据库。对于已经创建好的数据库,是无法修改代码页参数的,因此必须删除重建。
db2 => db2start
db2 => drop database db2test
db2 => create database db2test using codeset utf-8 territory CN
db2 => list database directory
下面提供了一个连接测试程序(修改自互联网)
import java.sql.*;
public class ConnDB2 {
/** *//**
* @param args
*/
public static void main(String[] args) {
String driver = "com.ibm.db2.jcc.DB2Driver";
String url = "jdbc:db2://db2-ip:50000/db2test;
String userName = "db2admin";
String passWord = "123456";
Connection conn = null;
Statement st = null;
ResultSet rs = null;
String sql = null;
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url, userName, passWord);
st = conn.createStatement();
st.execute("set current schema lectery");
sql = new String("SELECT book_name FROM book");
rs = st.executeQuery(sql);
while(rs.next()) {
System.out.println(rs.getString(1));
}
System.out.println(conn);
conn.close();
} catch (Exception e) {
System.out.println("error:" + e.getMessage() );
System.out.println(e.toString());
}
}
}
连接驱动
分享到:
相关推荐
Protocol not supported(解决方案).md
在软件开发过程中,遇到...“Operation Not Supported”问题的解决方法通常需要结合具体情况进行分析和处理。在处理过程中,合理利用官方文档、社区资源、版本信息和权限管理等工具将有助于找到问题的解决方案。
解决SVN上传提示Empty directoriesis not supported 解决SVN上传提示Empty directoriesis not supported
网上各种教程无法解决这个工具提示 not supported not listening问题,这个安装包给出了所有需要的文件,并给出了详细的指引。 绝大多数情况你会安装成功。如果你成功了,或者失败了,请给我评论。大家看评论区。
网上各种教程无法解决这个工具提示 not supported not listening问题,这个安装包给出了所有需要的文件,并给出了详细的指引。 绝大多数情况你会安装成功。如果你成功了,或者失败了,请给我评论。大家看评论区。 ...
ThinkPHP6.1 Filesystem Driver aliyun not supported
当您遇到"405 - HTTP method GET is not supported by this URL"这样的问题时,通常意味着您的服务器端代码没有正确处理GET请求,或者请求被误定向到了一个不期望GET方法的Servlet。 首先,我们需要理解HTTP协议中...
File Not Supported(解决方案).md
Oracle数据库在运行过程中,经常会遇到各种错误代码,错误代码ORA-00845是其中的一个,它是指“MEMORY_TARGET not supported on this system”。这个错误一般发生在尝试在不支持MEMORY_TARGET参数的系统上设置该参数...
这原本可以通过rdpWrap实现支持,但rdpWrap没持续更新,win10更新后就会产生listener state not supported 问题。当前上传版本解决了此问题,在64位win10.0.19042.1052上测试正常。 解压后双击 安装.bat 进行安装 ...
Grid Layout Not Supported(解决方案).md
Encryption algorithm not supported(解决方案).md
处理"NotSupportedError"需要我们有耐心和细心,通过阅读错误信息、查看文档、检查代码和更新库或框架等步骤,我们通常可以找到解决问题的方法。而为了预防这个问题的发生,我们应该保持库或框架的最新状态,理解并...
Office安装错误Per-user install not supported.txt
operation not supported解决方案(亲测可用)