Topic
  • 2 replies
  • Latest Post - ‏2012-09-13T22:18:12Z by SystemAdmin
sailsoft
sailsoft
3 Posts

Pinned topic how to set infomix IfxNEWCODESET to solve messy code?

‏2012-09-13T08:00:57Z |
the example :
public static void main(String[] args) {
com.informix.jdbcx.IfxXADataSource xaDS = new com.informix.jdbcx.IfxXADataSource();
xaDS.setIfxIFX_USE_STRENC(true);
xaDS.setDatabaseName("testdb");
xaDS.setUser("admin");
xaDS.setPassword("12345");
xaDS.setServerName("ifxserver");
xaDS.setPortNumber(10001);
xaDS.setIfxIFXHOST("100.100.100.10");
xaDS.setIfxNEWCODESET("gbk,8859-1,819");
xaDS.setIfxNEWLOCALE("en_us,zh_cn");
try {
// Connection conn = xaDS.getXAConnection().getConnection();
Class.forName("com.informix.jdbc.IfxDriver");
Connection conn = DriverManager.getConnection("jdbc:informix-sqli://100.100.100.10:10001/testdb:informixserver=ifxserver;user=admin;password=123;newlocale=en_us,zh_cn;newcodeset=gbk,8859-1,819;IFX_USE_STRENC=true;");
PreparedStatement pstmt = conn.prepareStatement("select * from awardcfg");
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
String fname = new String(rs.getString("award_name").getBytes("iso8859-1"),"gbk");
System.out.println(rs.getString("award_name") + " the award_name is " + fname + " award_id " + rs.getString("award_id"));
}
rs.close();
pstmt.close();
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

ds.close();
}

when i use IfxXADataSource the return result is messy code,the same configuration if i use IfxDriver it's right,

but i want use XA datasource, How to set the IfxXADataSource property?
Updated on 2012-09-13T22:18:12Z at 2012-09-13T22:18:12Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    1143 Posts

    Re: how to set infomix IfxNEWCODESET to solve messy code?

    ‏2012-09-13T10:54:05Z  
    Hi,

    as far as I know NEWCODESET does not work with IfxXADataSource and JDK 1.4 and higher.
    You should use java.nio.* for codeset conversion.

    Kind regards,
    Marion
  • SystemAdmin
    SystemAdmin
    1143 Posts

    Re: how to set infomix IfxNEWCODESET to solve messy code?

    ‏2012-09-13T22:18:12Z  
    Hi,

    as far as I know NEWCODESET does not work with IfxXADataSource and JDK 1.4 and higher.
    You should use java.nio.* for codeset conversion.

    Kind regards,
    Marion
    Seems like the problem might have something to do with the JVM since Informix JDBC driver uses JDK globalization API for code conversion, like Marion said in the previous update.

    You may try to force JVM to use the right codeset with the -Dfile.encoding option at runtime or the -encoding option at compiling time to see if it would help.