2007年09月01日

OUC2008也是Shanghai Online Used Car平台的简称,现在开发进度正常,已经完成车辆展示的部分,现在已经进入车辆交易环节的制作,现在整个平台的雏形已经建立,它将在不久的未来成为统一上海市二手车交易、实现超越51Car的一个公共服务平台。

2007年05月17日

这些天在Tapestry下制作Table的例子,感觉Tapestry封装的太厉害了,加在Contrib:Table这个控件是由第三方的人开发的,一直在没有头绪中摸索。昨天晚上睡觉的时候,还在想用ResultSet传入ResultSetIterator这个实现Iterator的类来做,因为Oracle中OracleResultSetImpl不是串行化的,所以这条路被“枪毙”掉了。后来发现,我们那里的ehoole写的一个数据集类(DataSet),它本身就是一个Vector,而Vector恰恰可以Vector.iterator()来返回Iterator迭代器,^_^,在这个方向下,我终于成功了。

特此纪念一下!

2005年09月22日

package com.sucem.net;

import java.io.*;
import java.net.*;
import java.util.*;

/**
 * <p>标题: HTTP文件下载模块</p>
 *
 * <p>描述: </p>
 *
 * <p>版权: Copyright (c) 2005</p>
 *
 * <p>公司: </p>
 *
 * @作者 not attributable
 * @版本 1.0.0.0
 */
public class HttpGet {
    private static int BUFFER_SIZE=512000;    // 缓冲区大小
    private Vector vDownload=new Vector();  // URL列表
    private Vector vFileList=new Vector();  // 下载后保存文件名的列表

    public HttpGet() {
    }
    // 清除下载列表
    public void resetList(){
        vDownload.clear();
        vFileList.clear();
    }
    // 增加下载列表项
    public void addItems(String url,String filename){
        vDownload.add(url);
        vFileList.add(filename);
    }
    // 根据列表下载资源
    public void downLoadByList() throws Exception {
        String url=null;
        String filename=null;
        //按列表顺序保存资源
        for(int i=0;i<vDownload.size();i++){
            url=(String)vDownload.get(i);
            filename=(String)vFileList.get(i);
            try{
                saveToFile(url,filename);
            }
            catch(IOException err){
            }
        }
    }
    // 将HTTP资源另存为文件
    public void saveToFile(String destUrl,String fileName) throws Exception{
        FileOutputStream fos=null;
        BufferedInputStream bis=null;
        HttpURLConnection httpUrl=null;
        URL url=null;
        byte[] buf=new byte[BUFFER_SIZE];
        int size=0;
        // 建立链接
        url=new URL(destUrl);
        httpUrl=(HttpURLConnection)url.openConnection();
        // 连接指定的资源
        httpUrl.connect();
        // 获取网络输入流
        bis=new BufferedInputStream(httpUrl.getInputStream());
        // 建立文件
        fos=new FileOutputStream(fileName);
        while((size=bis.read(buf))!=-1)
            fos.write(buf,0,size);
        fos.close();
        bis.close();
        httpUrl.disconnect();
    }
    public void saveToFile1(String destUrl,String fileName) throws Exception {
      URL url=new URL(destUrl);
      URLConnection urlConn=url.openConnection();
      InputStream is=urlConn.getInputStream();
      OutputStream os=new FileOutputStream(fileName);
      int end;
      while((end=is.read())!=-1)  os.write(end);
      is.close();
      os.close();
    }
 }

 public static void SetDateTime(String year, String month, String day,
                                 String hour, String minute, String second) throws
      IOException,
      InterruptedException {
    String command1 = "cmd /c date " + year + "-" + month + "-" + day;
    Process p = Runtime.getRuntime().exec(command1);
    p.waitFor();
    p.destroy();
    String command2 = "cmd /c time " + hour + ":" + minute + ":" + second;
    Process q = Runtime.getRuntime().exec(command2);
    q.waitFor();
    q.destroy();
  }

package com.sucem.util;

import java.net.*;
import java.security.*;
import java.util.*;

public class RandomGUID
    extends Object {
  public String valueBeforeMD5 = "";
  public String valueAfterMD5 = "";
  private static Random myRand;
  private static SecureRandom mySecureRand;

  static {
    mySecureRand = new SecureRandom();
    long secureInitializer = mySecureRand.nextLong();
    myRand = new Random(secureInitializer);
  }

  public RandomGUID() {
    getRandomGUID(false);
  }

  public RandomGUID(boolean secure) {
    getRandomGUID(secure);
  }

  private void getRandomGUID(boolean secure) {
    MessageDigest md5 = null;
    StringBuffer sbValueBeforeMD5 = new StringBuffer();
    try {
      md5 = MessageDigest.getInstance("MD5");
    }
    catch (NoSuchAlgorithmException e) {
      System.out.println("Error: " + e);
    }
    try {
      InetAddress id = InetAddress.getLocalHost();
      long time = System.currentTimeMillis();
      long rand = 0;
      if (secure) {
        rand = mySecureRand.nextLong();
      }
      else {
        rand = myRand.nextLong();
      }
      sbValueBeforeMD5.append(id.toString());
      //sbValueBeforeMD5.append(":");
      sbValueBeforeMD5.append(Long.toString(time));
      //sbValueBeforeMD5.append(":");
      sbValueBeforeMD5.append(Long.toString(rand));
      valueBeforeMD5 = sbValueBeforeMD5.toString();
      md5.update(valueBeforeMD5.getBytes());
      byte[] array = md5.digest();
      StringBuffer sb = new StringBuffer();
      for (int j = 0; j < array.length; ++j) {
        int b = array[j] & 0xFF;
        if (b < 0×10) {
          sb.append(‘0′);
        }
        sb.append(Integer.toHexString(b));
      }
      valueAfterMD5 = sb.toString();
    }
    catch (UnknownHostException e) {
      System.out.println("Error:" + e);
    }
  }

  public String toString() {
    String raw = valueAfterMD5.toUpperCase();
    StringBuffer sb = new StringBuffer();
    sb.append(raw.substring(0, 8));
    //sb.append("-");
    sb.append(raw.substring(8, 12));
    //sb.append("-");
    sb.append(raw.substring(12, 16));
    //sb.append("-");
    sb.append(raw.substring(16, 20));
    //sb.append("-");
    sb.append(raw.substring(20));
    return sb.toString();
  }
}

package com.sucem.util;

import java.io.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class NotePad {
  private String filename;
  private FileWriter filewriter;
  public NotePad(String filename) {
    this.filename = filename;
  }

  public void OpenFile(boolean isOverride) throws Exception {
    filewriter = new FileWriter(new File(filename), isOverride);
  }

  public void CloseFile() throws Exception {
    if (filewriter != null) {
      filewriter.close();
    }
  }

  public void addLine(String s) throws Exception {
    if (filewriter == null) {
      throw new Exception("please invoke OpenFile() before");
    }
    filewriter.write(s + System.getProperty("line.separator"));
  }

  public void show() throws Exception {
    if (filename == null || filename.length() == 0) {
      throw new Exception("filename is null");
    }
    Process p = Runtime.getRuntime().exec(
        new String[] {"notepad.exe", filename}
        );
  }

}

package com.sucem.test;

/**
 * <p>标题: </p>
 *
 * <p>描述: 软件用时测试</p>
 *
 * <p>版权: Copyright (c) 2005</p>
 *
 * <p>公司: </p>
 *
 * @作者:  * @版本 1.0
 */
public class Test {
  private static Test instance=new Test();
  private long startTime,endTime,interval;
 
  public static Test getInstance(){
    return instance;
  }
  public void Start(){
    startTime=System.currentTimeMillis();
  }
  public long End(){
    endTime=System.currentTimeMillis();
    interval=endTime-startTime;
    startTime=System.currentTimeMillis();
    return interval;
  }
  public static void main(String[] args) {
    Test test = new Test();
  }
}

2005年08月22日

package com.sucem.util;

import java.sql.*;
import java.util.*;

import javax.swing.table.*;

/**
 * <p>Title: 传入ResultSet返回TableModel装入JTable</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author 

 * @version 1.0
 */
public class ResultSetTableModel
    extends AbstractTableModel {
  protected Vector columnHeaders;
  protected Vector tableData;

  public ResultSetTableModel(ResultSet rset) throws SQLException, Exception {
    //Vector rowData;
    ResultSetMetaData rsmd = rset.getMetaData();
    int count = rsmd.getColumnCount();
    columnHeaders = new Vector(count);
    tableData = new Vector();
    for (int i = 1; i <= count; i++) {
      columnHeaders.addElement(rsmd.getColumnName(i));
    }
    int j = 0;
    while (rset.next()) {
      j += 1;
      Vector rowData = new Vector(count);
      for (int i = 1; i <= count; i++) {
        rowData.addElement(rset.getObject(i));
      }
      tableData.addElement(rowData);
    }
    if (j == 0) {
      throw new Exception("没有数据");
    }
  }

  public int getColumnCount() {
    return columnHeaders.size();
  }

  public int getRowCount() {
    return tableData.size();
  }

  public Object getValueAt(int rowIndex, int columnIndex) {
    Vector rowData = (Vector) (tableData.elementAt(rowIndex));
    return rowData.elementAt(columnIndex);
  }

  public boolean isCellEditable(int rowIndex, int columnIndex) {
    return false;
  }

  public String getColumnName(int columnIndex) {
    return (String) (columnHeaders.elementAt(columnIndex));
  }

}

package com.sucem.net;

import java.io.*;
import java.net.*;
import java.util.*;

/**
 * <p>标题: 查验系统:HTTP文件下载模块</p>
 *
 * <p>描述: </p>
 *
 * <p>版权: Copyright (c) 2005</p>
 *
 * <p>公司: </p>
 *

 * @作者 not attributable
 * @版本 1.0.0.0
 */
public class HttpGet {
    private static int BUFFER_SIZE=512000;    // 缓冲区大小
    private Vector vDownload=new Vector();  // URL列表
    private Vector vFileList=new Vector();  // 下载后保存文件名的列表

    public HttpGet() {
    }
    // 清除下载列表
    public void resetList(){
        vDownload.clear();
        vFileList.clear();
    }
    // 增加下载列表项
    public void addItems(String url,String filename){
        vDownload.add(url);
        vFileList.add(filename);
    }
    // 根据列表下载资源
    public void downLoadByList() throws Exception {
        String url=null;
        String filename=null;
        //按列表顺序保存资源
        for(int i=0;i<vDownload.size();i++){
            url=(String)vDownload.get(i);
            filename=(String)vFileList.get(i);
            try{
                saveToFile(url,filename);
            }
            catch(IOException err){
            }
        }
    }
    // 将HTTP资源另存为文件
    public void saveToFile(String destUrl,String fileName) throws Exception{
        FileOutputStream fos=null;
        BufferedInputStream bis=null;
        HttpURLConnection httpUrl=null;
        URL url=null;
        byte[] buf=new byte[BUFFER_SIZE];
        int size=0;
        // 建立链接
        url=new URL(destUrl);
        httpUrl=(HttpURLConnection)url.openConnection();
        // 连接指定的资源
        httpUrl.connect();
        // 获取网络输入流
        bis=new BufferedInputStream(httpUrl.getInputStream());
        // 建立文件
        fos=new FileOutputStream(fileName);
        while((size=bis.read(buf))!=-1)
            fos.write(buf,0,size);
        fos.close();
        bis.close();
        httpUrl.disconnect();
    }
    public void saveToFile1(String destUrl,String fileName) throws Exception {
      URL url=new URL(destUrl);
      URLConnection urlConn=url.openConnection();
      InputStream is=urlConn.getInputStream();
      OutputStream os=new FileOutputStream(fileName);
      int end;
      while((end=is.read())!=-1)  os.write(end);
      is.close();
      os.close();
    }
    public static void main(String[] argv){
        HttpGet oInstance=new HttpGet();
        try{
            // oInstance.addItems("http://10.0.0.201/Download/close.jpg","./close.jpg");
            oInstance.addItems("http://10.0.0.201/Download/cyd.txt","./cyd.txt");
            // oInstance.addItems("http://10.0.0.201/Download/config.txt","./config.txt");
            oInstance.addItems("http://10.0.0.201/Download/VehExamineW.exe","./VehExamineW.exe");
            oInstance.downLoadByList();
            // int t2=date.getDate();
            // System.out.println((double)t2-(double)t1);
        }catch(Exception err){

        }
    }
}

package com.sucem.db;

import java.sql.*;

import com.sucem.common.*;

/**
 * <p>标题: 数据库操作类</p>
 *
 * <p>描述: 通过JDBC访问oracle,封装了所有的SQL操作</p>
 *
 * <p>版本: Copyright (c) 2005</p>
 *
 * <p>公司: </p>
 *
 * @作者:   
 * @version 1.0
 */
public class DBUtil {
  private Connection _connection = null;
  private Statement _stmt = null;
  private ResultSet _resultset = null;
  private static DBUtil _instance = null;

  public DBUtil() throws SucemException {
    _connection = ConnMgmt.getInstance().GetConnection();
  }

  public static DBUtil getInstance() throws SucemException {
    if (_instance == null) {
      _instance = new DBUtil();
    }
    return _instance;
  }

  public void executeTransation(String sql) throws SucemException {
    try {
      _connection.setAutoCommit(false);
      _stmt = _connection.createStatement();
      _stmt.executeUpdate(sql);
      SaveAndExit();
    }
    catch (SQLException ex) {
      RollBack();
      throw new SucemException(ex);
    }
  }

  public void executeTransation(String[] sql) throws SucemException {
    try {
      _connection.setAutoCommit(false);
      _stmt = _connection.createStatement();
      int maxLength = sql.length;
      for (int i = 0; i < maxLength; i++) {
        _stmt.execute(sql[i].toString().trim());
      }
      SaveAndExit();
    }
    catch (SQLException ex) {
      RollBack();
      throw new SucemException(ex);
    }
  }

  public DataSet QueryDataSet(String sql) throws SucemException {
    DataSet ds = null;
    try {
      _stmt = _connection.createStatement();
      _resultset = _stmt.executeQuery(sql);
      ds = new DataSet(_resultset);
    }
    catch (SQLException ex) {
      throw new SucemException(ex);
    }
    finally {
      Close();
    }
    return ds;
  }

  public void SaveAndExit() throws SucemException {
    try {
      _connection.commit();
      Close();
    }
    catch (SQLException ex) {
      throw new SucemException(ex);
    }
  }

  public void RollBack() throws SucemException {
    try {
      _connection.rollback();
      Close();
    }
    catch (SQLException ex) {
      throw new SucemException(ex);
    }
  }

  public void Close() throws SucemException {
    try {
      if (_stmt != null) {
        _stmt.close();
      }
      if (_resultset != null) {
        _resultset.close();
      }
      if (_connection != null) {
        _connection.close();
      }
    }
    catch (SQLException ex) {
      throw new SucemException(ex);
    }
  }

  protected void finalize() throws SucemException {
    Close();
    _resultset = null;
    _stmt = null;
    _connection = null;
  }

  public static void main(String[] args) {
    try {
      DBUtil db = new DBUtil();
      db.executeTransation("update cyd set jg=’05′ where cyh=’200508110540′");
    }
    catch (SucemException ex) {
    }
  }
}