informix使用得一些小常识

在java中连接informix
网上有些关于这个的文章,纯粹扯淡(关于驱动的jar包,解决中文乱码的),
仅需一个jar包,
1,添加驱动
然后如果用maven管理项目
http://mvnrepository.com/artifact/com.ibm.informix/jdbc/4.10.9 以上这个网址下载到本地仓
或者将

<dependency>
    <groupId>com.ibm.informixgroupId>
    <artifactId>jdbcartifactId>
    <version>4.10.9version>
dependency>

此段代码复制到项目的pom.xml中
2.代码中书写url

String url= "jdbc:informix-sqli://"+ip+":"+port+"/"+databaseName+":INFORMIXSERVER="+serverName+";NEWCODESET=GB2312,8859-1,819;IFX_USE_STRENC=true";

对url中的个参数做解释:ip 数据库的ip地址,port 数据库端口号,databaseName 数据库名称,
serverName 数据库服务名称(安装informix数据库时创建),NEWCODESET中三个编码依次分别是
(1)客户端存入或查询出数据使用的编码集(可以utf8,GB2312,gb18030,以上三种支持中文),按照格式随意指定字符集,只要保持查询数据时候与插入数据时候使用的一致便不会乱码。
(2)数据库编码集(可以是8859-1,gb18030-2000(支持中文)),改字符集是在安装时候在数据库配置文件中指定的,并且环境变量生效的,可以使用sql:select site from informix.systables where tabname = ’ GL_COLLATE’ 查询出来,活着在环境变量里查看。
(3)编码集在informix字典中的编号 例如819即iso8859-1,5488 即gb18030(本人目前只是用过以上两种,并不表示只支持此两种),翻过informix的驱动支持的如下:

static {
        if (IfxToJdkEncodingTable == null) {
            IfxToJdkEncodingTable = new Hashtable();
            IfxToJdkEncodingTable.put("8859-1", "ISO8859_1");
            IfxToJdkEncodingTable.put("8859-2", "ISO8859_2");
            IfxToJdkEncodingTable.put("8859-3", "ISO8859_3");
            IfxToJdkEncodingTable.put("8859-4", "ISO8859_4");
            IfxToJdkEncodingTable.put("8859-5", "ISO8859_5");
            IfxToJdkEncodingTable.put("8859-6", "ISO8859_6");
            IfxToJdkEncodingTable.put("8859-7", "ISO8859_7");
            IfxToJdkEncodingTable.put("8859-8", "ISO8859_8");
            IfxToJdkEncodingTable.put("8859-9", "ISO8859_9");
            IfxToJdkEncodingTable.put("8859-13", "ISO8859_13");
            IfxToJdkEncodingTable.put("8859-15", "ISO8859_15_FDIS");
            IfxToJdkEncodingTable.put("Latin-9", "ISO8859_15_FDIS");
            IfxToJdkEncodingTable.put("ASCII", "ASCII");
            IfxToJdkEncodingTable.put("sjis-s", "SJIS");
            IfxToJdkEncodingTable.put("utf8", "UTF8");
            IfxToJdkEncodingTable.put("big5", "Big5");
            IfxToJdkEncodingTable.put("CP1250", "Cp1250");
            IfxToJdkEncodingTable.put("CP1251", "Cp1251");
            IfxToJdkEncodingTable.put("CP1252", "Cp1252");
            IfxToJdkEncodingTable.put("CP1253", "Cp1253");
            IfxToJdkEncodingTable.put("CP1254", "Cp1254");
            IfxToJdkEncodingTable.put("CP1255", "Cp1255");
            IfxToJdkEncodingTable.put("CP1256", "Cp1256");
            IfxToJdkEncodingTable.put("CP1257", "Cp1257");
            IfxToJdkEncodingTable.put("cp949", "KSC5601");
            IfxToJdkEncodingTable.put("KS5601", "KSC5601");
            IfxToJdkEncodingTable.put("ksc", "KSC5601");
            IfxToJdkEncodingTable.put("gb", "GBK");
            IfxToJdkEncodingTable.put("GB2312-80", "GBK");
            IfxToJdkEncodingTable.put("cp936", "GBK");
            IfxToJdkEncodingTable.put("CP850", "Cp850");
            IfxToJdkEncodingTable.put("CP866", "Cp866");
            IfxToJdkEncodingTable.put("KOI-8", "KOI8_R");
            IfxToJdkEncodingTable.put("CP852", "Cp852");
            IfxToJdkEncodingTable.put("ujis", "EUC_JP");
            IfxToJdkEncodingTable.put("thai620", "MS874");
            IfxToJdkEncodingTable.put("sjis", "SJIS");
            IfxToJdkEncodingTable.put("big5-HKSCS", "Big5-HKSCS");
            IfxToJdkEncodingTable.put("big5HKSCS", "Big5-HKSCS");
            IfxToJdkEncodingTable.put("cp_949", "MS949");
            IfxToJdkEncodingTable.put("GB18030-2000", "GB18030");
        }

        if (IfxNoToJdkEncodingTable == null) {
            IfxNoToJdkEncodingTable = new Hashtable();
            IfxNoToJdkEncodingTable.put("819", "ISO8859_1");
            IfxNoToJdkEncodingTable.put("912", "ISO8859_2");
            IfxNoToJdkEncodingTable.put("57346", "ISO8859_3");
            IfxNoToJdkEncodingTable.put("57347", "ISO8859_4");
            IfxNoToJdkEncodingTable.put("915", "ISO8859_5");
            IfxNoToJdkEncodingTable.put("1089", "ISO8859_6");
            IfxNoToJdkEncodingTable.put("813", "ISO8859_7");
            IfxNoToJdkEncodingTable.put("916", "ISO8859_8");
            IfxNoToJdkEncodingTable.put("920", "ISO8859_9");
            IfxNoToJdkEncodingTable.put("57391", "ISO8859_15_FDIS");
            IfxNoToJdkEncodingTable.put("364", "ASCII");
            IfxNoToJdkEncodingTable.put("932", "SJIS");
            IfxNoToJdkEncodingTable.put("57372", "UTF8");
            IfxNoToJdkEncodingTable.put("57352", "Big5");
            IfxNoToJdkEncodingTable.put("1250", "Cp1250");
            IfxNoToJdkEncodingTable.put("1251", "Cp1251");
            IfxNoToJdkEncodingTable.put("1252", "Cp1252");
            IfxNoToJdkEncodingTable.put("1253", "Cp1253");
            IfxNoToJdkEncodingTable.put("1254", "Cp1254");
            IfxNoToJdkEncodingTable.put("1255", "Cp1255");
            IfxNoToJdkEncodingTable.put("1256", "Cp1256");
            IfxNoToJdkEncodingTable.put("1257", "Cp1257");
            IfxNoToJdkEncodingTable.put("57356", "KSC5601");
            IfxNoToJdkEncodingTable.put("57357", "GBK");
            IfxNoToJdkEncodingTable.put("850", "Cp850");
            IfxNoToJdkEncodingTable.put("866", "Cp866");
            IfxNoToJdkEncodingTable.put("57382", "KOI8_R");
            IfxNoToJdkEncodingTable.put("852", "Cp852");
            IfxNoToJdkEncodingTable.put("57351", "EUC_JP");
            IfxNoToJdkEncodingTable.put("57373", "MS874");
            IfxNoToJdkEncodingTable.put("57350", "SJIS");
            IfxNoToJdkEncodingTable.put("1375", "Big5-HKSCS");
            IfxNoToJdkEncodingTable.put("949", "MS949");
            IfxNoToJdkEncodingTable.put("5488", "GB18030");
            IfxNoToJdkEncodingTable.put("57390", "ISO8859_13");
        }

        if (IfxToJdkLocaleTable == null) {
            IfxToJdkLocaleTable = new Hashtable();
            IfxToJdkLocaleTable.put("ar_ae", "ar_AE");
            IfxToJdkLocaleTable.put("ar_bh", "ar_BH");
            IfxToJdkLocaleTable.put("ar_kw", "ar_KW");
            IfxToJdkLocaleTable.put("ar_om", "ar_OM");
            IfxToJdkLocaleTable.put("ar_qa", "ar_QA");
            IfxToJdkLocaleTable.put("ar_sa", "ar_SA");
            IfxToJdkLocaleTable.put("bg_bg", "bg_BG");
            IfxToJdkLocaleTable.put("ca_es", "ca_ES");
            IfxToJdkLocaleTable.put("cs_cz", "cs_CZ");
            IfxToJdkLocaleTable.put("da_dk", "da_DK");
            IfxToJdkLocaleTable.put("de_at", "de_AT");
            IfxToJdkLocaleTable.put("de_ch", "de_CH");
            IfxToJdkLocaleTable.put("de_de", "de_DE");
            IfxToJdkLocaleTable.put("el_gr", "el_GR");
            IfxToJdkLocaleTable.put("en_au", "en_AU");
            IfxToJdkLocaleTable.put("en_ca", "en_CA");
            IfxToJdkLocaleTable.put("en_gb", "en_GB");
            IfxToJdkLocaleTable.put("en_ie", "en_IE");
            IfxToJdkLocaleTable.put("en_nz", "en_NZ");
            IfxToJdkLocaleTable.put("en_us", "en_US");
            IfxToJdkLocaleTable.put("es_ar", "es_AR");
            IfxToJdkLocaleTable.put("es_bo", "es_BO");
            IfxToJdkLocaleTable.put("es_cl", "es_CL");
            IfxToJdkLocaleTable.put("es_co", "es_CO");
            IfxToJdkLocaleTable.put("es_cr", "es_CR");
            IfxToJdkLocaleTable.put("es_ec", "es_EC");
            IfxToJdkLocaleTable.put("es_es", "es_ES");
            IfxToJdkLocaleTable.put("es_gt", "es_GT");
            IfxToJdkLocaleTable.put("es_mx", "es_MX");
            IfxToJdkLocaleTable.put("es_pa", "es_PA");
            IfxToJdkLocaleTable.put("es_pe", "es_PE");
            IfxToJdkLocaleTable.put("es_py", "es_PY");
            IfxToJdkLocaleTable.put("es_sv", "es_SV");
            IfxToJdkLocaleTable.put("es_uy", "es_UY");
            IfxToJdkLocaleTable.put("es_ve", "es_VE");
            IfxToJdkLocaleTable.put("et_ee", "et_EE");
            IfxToJdkLocaleTable.put("fi_fi", "fi_FI");
            IfxToJdkLocaleTable.put("fr_be", "fr_BE");
            IfxToJdkLocaleTable.put("fr_ca", "fr_CA");
            IfxToJdkLocaleTable.put("fr_ch", "fr_CH");
            IfxToJdkLocaleTable.put("fr_fr", "fr_FR");
            IfxToJdkLocaleTable.put("hr_hr", "hr_HR");
            IfxToJdkLocaleTable.put("hu_hu", "hu_HU");
            IfxToJdkLocaleTable.put("is_is", "is_IS");
            IfxToJdkLocaleTable.put("it_ch", "it_CH");
            IfxToJdkLocaleTable.put("it_it", "it_IT");
            IfxToJdkLocaleTable.put("iw_il", "iw_IL");
            IfxToJdkLocaleTable.put("ja_jp", "ja_JP");
            IfxToJdkLocaleTable.put("ko_kr", "ko_KR");
            IfxToJdkLocaleTable.put("lv_lv", "lv_LV");
            IfxToJdkLocaleTable.put("mk_mk", "mk_MK");
            IfxToJdkLocaleTable.put("nl_be", "nl_BE");
            IfxToJdkLocaleTable.put("nl_nl", "nl_NL");
            IfxToJdkLocaleTable.put("no_no", "no_NO");
            IfxToJdkLocaleTable.put("pl_pl", "pl_PL");
            IfxToJdkLocaleTable.put("pt_br", "pt_BR");
            IfxToJdkLocaleTable.put("pt_pt", "pt_PT");
            IfxToJdkLocaleTable.put("ro_ro", "ro_RO");
            IfxToJdkLocaleTable.put("ru_ru", "ru_RU");
            IfxToJdkLocaleTable.put("sh_yu", "sh_YU");
            IfxToJdkLocaleTable.put("sk_sk", "sk_SK");
            IfxToJdkLocaleTable.put("sv_se", "sv_SE");
            IfxToJdkLocaleTable.put("th_th", "th_TH");
            IfxToJdkLocaleTable.put("tr_tr", "tr_TR");
            IfxToJdkLocaleTable.put("uk_ua", "uk_UA");
            IfxToJdkLocaleTable.put("zh_cn", "zh_CN");
            IfxToJdkLocaleTable.put("zh_tw", "zh_TW");
            IfxToJdkLocaleTable.put("zh_hk", "zh_HK");
        }

所以只要保证(2)与(3)是匹配的,并且(2)是实际数据库编码集,并且(1)与插入数据使用的一致便不会乱码(千万不要在各个参数中加空格,加上也会乱码)。

你可能感兴趣的:(informix使用得一些小常识)