• 2005年10月19日

    javadbf中文问题的解决

    Tag:DB j2se Java

    前面shuyanxu朋友提到javadbf(http://fireshort.blogbus.com/logs/2005/09/1420670.html)的中文支持问题,由于我测试得不够仔细就忽略掉了。最近发现读取中文是没有问题的,但写入dbf的时候就会产生乱码。

    设了几个断点之后跟踪发现是Utils中的textPadding方法有错,原来的方法是

    代码:
       public static byte[] textPadding( String text, String characterSetName, int length, int alignment,
       byte paddingByte) throws java.io.UnsupportedEncodingException {

          if( text.length() >= length) {

             return text.substring( 0, length).getBytes( characterSetName);
          }

          byte byte_array[] = new byte[ length];
          Arrays.fill( byte_array, paddingByte);

          switch( alignment) {

             case ALIGN_LEFT:
                System.arraycopy( text.getBytes( characterSetName), 0, byte_array, 0, text.length());
                break;

             case ALIGN_RIGHT:
                int t_offset = length - text.length();
                System.arraycopy( text.getBytes( characterSetName), 0, byte_array, t_offset, text.length());
                break;
             }   

          return byte_array;
       }

    我改为了
    代码:
        public static byte[] textPadding(String text,String characterSetName,
                int length,int alignment,byte paddingByte)
                throws java.io.UnsupportedEncodingException
        {
            byte[] srcByteArray=text.getBytes(characterSetName);
            byte[] dstByteArray=new byte[length];
            Arrays.fill(dstByteArray,paddingByte);

            int dstLength=0;
            if(srcByteArray.length>=length)
            {
                dstLength=length%2==0?length:length-1;
            }else
            {
                dstLength=srcByteArray.length;
            }

            switch(alignment)
            {

            case ALIGN_LEFT:
                System.arraycopy(srcByteArray,0,dstByteArray,0,dstLength);
                break;

            case ALIGN_RIGHT:
                System.arraycopy(srcByteArray,0,dstByteArray,length-dstLength,dstLength);
                break;
            }
            return dstByteArray;
        }

    中文输出完全正常了。

  • 2005年09月08日

    操作dbf的类库

    Tag:DB Java j2se
    操作DBF文件的类库建议采用javadbf。

    名称为javadbf的开源项目有两个,一个是
    http://javadbf.dev.java.net,因为这个项目缺少文档而代码注释不知是何国鸟语,故不选;另一个是http://sarovar.org/projects/javadbf/,印度人的开源项目,文档完备,注释多到冗余,在http://sarovar.org上下载次数排第6,LGPL。

    通过对一些dbf文件进行读写测试,印度人的这个项目完全符合我们项目的需要。我们将采用此javadbf作为操作dbf的工具。
  • 首先修改%windir%\my.ini,增加:
    引用:

    [client]
    default-character-set=gbk

    mysql自带的东东都是在%windir%\my.ini设置,包括命令行控制台)
    其次,在配置ODBC源时,选上Read Options From my.cnf,如下图,即可。

  • 2005年07月21日

    SQL Server安装问题

    Tag:DB

    You receive a "Command line option syntax error" error message when you install SQL Server 2000 SP3

    今天安装SQL Server的时候出现了这个问题,之前记得在服务器上成功安装过的。

    google之,发现MS已经有解释了(微软的文档功夫还是相当不错的,就是你总也得不到问题的真正原因):
    http://support.microsoft.com/?kbid=841487

    引用:
    You run the SQL Server 2000 SP3 Setup.bat file from a folder that contains double-byte character set (DBCS) characters in the folder name.

    也就是在安装目录里不能有中文。

    奇怪的是:以前也是在服务器上安装的,安装源也没有移动过,不知道怎么就有这个问题了。

    Anyway,SQL Server还是装上了。

  • 早上在JavaEye看到Robbin说:
    引用:

    DBCP的bug非常多,因此Hibernate3已经不再支持DBCP连接池,而推荐使用C3PO。建议你更换数据库连接池。


    然后跑去Hibernate官方论坛看,果然,在Please migrate away from DBCP看到Gavin说:
    引用:
    Guys, after many problems with DBCP, I have decided to remove built-in support for DBCP from Hibernate3, and deprecate DBCP in Hibernate 2.1. I advise everyone to migrate away from DBCP to something that actually works, like C3P0 or Proxool.

    (If you /must/ use DBCP, you can always write your own connection provider.)

    Actually, it is probably about time we remove any remaining dependencies to Apache commons stuff, since historically they have caused just /so/ much trouble. The only Apache things that do seem to work very well are Ant and log4j. Even commons-logging is a PIA, especially in Tomcat.


    这个台湾Guy也是如此建议
    引用:
    挑選觀念: 是否認為 jakarta 是唯一選擇
    是的話, 採用 commons-dbcp ; 不是的話, 採用 proxool / c3p0


    Jakarta-commons社区对Hibernate官方不支持DBCP的应对:
    http://wiki.apache.org/jakarta-commons/DBCP/Hibernate