Java获取随机字符串

  1. import java.util.Random;
  2.  
  3. public static String getRandomString(int length) {
  4.     StringBuffer buffer = new StringBuffer("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
  5.     StringBuffer sb = new StringBuffer();
  6.     Random r = new Random();
  7.     int range = buffer.length();
  8.     for (int i = 0; i < length; i ++) {
  9.         sb.append(buffer.charAt(r.nextInt(range)));
  10.     }
  11.     return sb.toString();
  12. }

这个没啥意思,就是随机数用的不多,每次要用都记不住,在这里备个份@@

标签:, ,

相关日志

PreparedStatement的怪异问题

详细代码和数据库(Oracle)见附件,本来很简单的事情没想到让我碰到了诡异的问题。

PreparedStatement pstmt = conn.prepareStatement("update followcase set customitems=? where id=?");
pstmt.setString(1, customItems);
pstmt.setString(2, "4788");

这么写必然报java.sql.SQLException: ORA-01461: 仅可以为插入 LONG 列的 LONG 值赋值。
如果把第二个参数值直接写入sql里就没问题,可以肯定的是原因必然是因为customItems超过一定长度,据smth上大大说当长度超过4000/3的时候可能会出问题。
现在为了解决无法插入的问题,只能先把除了customitems字段的insert进去,然后再来update它,晕。

PreparedStatement有什么特殊限制吗?

下载:测试代码及数据库

标签:, , ,

相关日志

咱也开始卖光盘了

经过两小时的手工作坊式包装,也像模像样了。
看看图,虽然比较简陋,不过也是我们单位第一个作为软件产品出售的,新注册公司的第一单业务吧~

20070328.jpg

标签:,

FTPClient中retrieveFileStream的用法

工作需要使用了org.apache.commons.net.ftp.FTPClient来操作FTP,记录一下心得。

这个类封装的很完善,使用起来也很简单,只是在使用retrieveFileStream的时候碰到了一点小问题,就是不知道怎么完成传输状态,尝试发送abor指令也不行。在咨询了bianbian和查看了源代码之后看到这一段说明以后解决问题:

* You must close the InputStream when you
* finish reading from it. The InputStream itself will take care of
* closing the parent data connection socket upon being closed. To
* finalize the file transfer you must call
* {@link #completePendingCommand completePendingCommand } and
* check its return value to verify success.

代码如下:

  1. import org.apache.commons.net.ftp.FTPClient;
  2.  
  3. public class TestFTP {
  4.  
  5.     public static void main(String[] args) {
  6.         try {
  7.             FTPClient ftp = new FTPClient();
  8.             // initialize ftp connection
  9.             /*
  10.              *
  11.              */
  12.  
  13.             String remotefile = "test.xml";
  14.             InputStream is = null;
  15.  
  16.             is = ftp.retrieveFileStream(remotefile);
  17.  
  18.             if (is != null) {
  19.                 is.close();
  20.             }
  21.  
  22.             if (!ftp.completePendingCommand()) {
  23.                 ftp.logout();
  24.                 ftp.disconnect();
  25.             }
  26.            
  27.             // continue
  28.         } catch (SocketException e) {
  29.             // TODO Auto-generated catch block
  30.             e.printStackTrace();
  31.         } catch (IOException e) {
  32.             // TODO Auto-generated catch block
  33.             e.printStackTrace();
  34.         }
  35.     }
  36. }
标签:,

Windows Server 2003 Service Pack 2(32-bit x86) 中文版

下载:轻点

升级完没啥感觉,就是uxtheme.dll需要重新破解

补充:类似于升级SP1时候的问题,升级完后IE在解析脚本时出现很多问题,建议直接安装集成版而不是通过升级方式安装

win2003sp2.JPG

标签:, ,

相关日志
Page 1 of 512345»

京ICP备05059555号