飞翔吧

不做不说,说到做到

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

import java.io.*;
import java.util.*;
import java.text.*;
public class test{
 
public static void main(String[] args) throws Exception {
  
  /*
  String ss="1$2$3$";
  StringTokenizer token = new StringTokenizer(ss, "$", false);
 
  while(token.hasMoreElements()){
   String sToken = (token.nextElement()).toString();
     System.err.println(sToken);
     */
   /*
     GregorianCalendar calendar = new GregorianCalendar();
     System.out.println(calendar.getTime());
     System.out.println(new java.util.Date().getDate());
     */
  
   //date->text
     java.util.Date _date=new Date();
     SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd 24h:mm:ss");
        //  SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd 24h:mm:ss");
          String str1 = df.format(_date);
          System.out.println(str1);       
      
         
         SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd 24h:mm:ss");
         java.util.Date dt2 = df2.parse(str1); //text->date
         String str3 = df2.format(dt2);
         System.out.println(str3);
       
         
         DateFormat f = DateFormat.getDateTimeInstance();
         java.util.Date dt3 = f.parse("2001-04-05 21:30:00");                
         System.out.println(dt3);
        
                 
           
     
        //  java.sql.Date dd = new java.sql.Date(new java.util.Date().getTime());
         // System.out.print(dd);
  }
}



/*
 * 创建日期 2005-4-13
 *
 * 更改所生成文件模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
package com.startech.fjtbcj.dao.imp;

import java.sql.*;
import java.util.*;
import java.text.*;
import com.startech.database.*;
import com.startech.fjtbcj.bean.*;
import com.startech.fjtbcj.dao.SailInfoDAO;
import com.startech.log.*;
import com.startect.fjtbcj.exception.DAOException;

/**
 * @author Administrator
 *
 * 更改所生成类型注释的模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
public class SailInfoDAOImp implements SailInfoDAO {
 public static void main(String [] args)
 {
  SailInfoBean sailInfo = new SailInfoBean();
  sailInfo.setSailId("1");
  sailInfo.setSailTime("2005-04-13");
  sailInfo.setSailFlag("y");
  sailInfo.setCreateTime("2005-04-12");
  sailInfo.setAgentNum("11");
  sailInfo.setBStep("6");
  sailInfo.setNoUninstallNum(100);
  sailInfo.setUninstallNum(200);
  sailInfo.setAllNum(300);
  SailInfoDAOImp sailInfoImp= new SailInfoDAOImp();
  sailInfoImp.addSailInfo(sailInfo);
 }
 public void addSailInfo(SailInfoBean sailInfo) // throws DAOException
 {
  Connection connection = null;
  PreparedStatement prs = null;
     try
  {
   DBConnectionManager instance = DBConnectionManager.getInstance();
   connection =instance.getTransactionConnection();
   
   //string -> date
   DateFormat df = DateFormat.getDateInstance();
   java.util.Date sailTime = df.parse(sailInfo.getSailTime());
   java.util.Date createTime = df.parse(sailInfo.getCreateTime());  
   
   StringBuffer stringbuffer = new StringBuffer();
   stringbuffer.append("insert into SailInfoTbl values(?,?,?,?,?,?,?,?,?)");
   prs = connection.prepareStatement(stringbuffer.toString());
   prs.setString(1,sailInfo.getSailId());
   prs.setDate(2,new java.sql.Date(sailTime.getTime())); //==
   prs.setString(3,sailInfo.getSailFlag());
   prs.setDate(4,new java.sql.Date(createTime.getTime()));
   prs.setString(5,sailInfo.getAgentNum());
   prs.setString(6,sailInfo.getBStep());
   prs.setInt(7,sailInfo.getNoUninstallNum());
   prs.setInt(8,sailInfo.getUninstallNum());
   prs.setInt(9,sailInfo.getAllNum());
   int i = prs.executeUpdate();
   boolean abort =(new Integer(i)).equals("1")? false:true;
   DBConnectionManager.closeTransactionConnection(connection,abort);
   }catch(Exception ex)
   {
    try{prs.close();
    connection.close();
    }catch(SQLException sqlex){
     Log.error(sqlex);
    }
    // throw new DAOException(ex);
                
   }finally{
    try{
     prs.close();
     connection.close();
   }
    catch(Exception e){Log.error(e);}
   }
   
    
 }
 public void modifSailInfo(SailInfoBean sailInfo)
 {
 }
 public void deleteSailInfo(SailInfoBean sailInfo)
 {  
 }
 public ArrayList getSailInfo(SailInfoBean sailInfo)
 {
  return new ArrayList();
 }
}

posted on 2005-04-13 18:05  飞翔  阅读(3865)  评论(0编辑  收藏  举报