爱生活·爱Java

The edge of beauty~

逝者如斯
网志分类
· 所有网志 (7)
· Java (1)
· Oracle (0)
· 银行业务 (0)
· 收藏 (3)
· 时尚生活 (1)
· 未分类 (2)
搜索本站
友情链接
· 我的歪酷 非非共享界

订阅 RSS

0003196

歪酷博客


« 上一篇: 下面是五个在XML文档中预定义好的实体 下一篇: 明星的Casual Glamor »
Gypsyfish @ 2006-07-24 13:41

  1. Sql Date与Date
    java.sql.Date 是针对SQL语句使用的,它只包含日期而没有时间部分;java.util.Date 是 java.sql.Date 的父类(注意拼写)前者是常用的表示时间的类,我们通常格式化或者得到当前时间都是用他.后者之后在读写数据库的时候用他,因为PreparedStament的setDate()的第2参数和ResultSet的getDate()方法的第2个参数都是java.sql.Date
    java.sql.Date date=new java.sql.Date();
    java.util.Date d=new java.util.Date (date.getTime());
    另:
    java.sql.Time sTime=new java.sql.Time(d.getTime());     
    java.sql.Timestamp stp=new java.sql.Timestamp(d.getTime());
  2. Java访问Oracle,设置动态SQL参数值Number类型的小数可用setString(), setBigDecimal()来设置. 用setFloat()会发生舍入误差.例如:9999999999.99 会变成10000000000.
  3. Java连接Oracle
      Connection conn = new OracleDriver().defaultConnection();
      String sql = "INSERT INTO user (id,name) " + "VALUES (?,?)";
      try {
          PreparedStatement pstmt = conn.prepareStatement(sql);
          pstmt.setString(1, id);
          pstmt.setString(2, name);
          pstmt.executeUpdate();
          pstmt.close();
        } catch (SQLException e) { }
  4. How to get current date string like '11-MAY-2006'
          Locale aLocale = new Locale("en");
          Calendar cal = new GregorianCalendar();
          Date date = cal.getTime();
          SimpleDateFormat sf = new SimpleDateFormat("dd-MMM-yyyy", aLocale);
          System.out.println("==============curdate="+sf.format(date));
  5. How to get the next day of a specified date?
    import java.util.GregorianCalendar;
    GregorianCalendar cal = new GregorianCalendar (2005, 8, 1, 0, 0,1);
    cal.add(GregorianCalendar.DAY_OF_MONTH, 1);
    Date nextday = cal.getTime();    
    -Please note that, the value used to set the MONTH time field in the calendar is 0-based. e.g., 0 for January.
  6. How to copy files
    import java.io.*;
    public class Copy {
      
    public static void main(String[] args) throws IOException {
        File inputFile 
    = new File("farrago.txt");
        File outputFile 
    = new File("outagain.txt");
        FileReader in 
    = new FileReader(inputFile);
        FileWriter out 
    = new FileWriter(outputFile);
        
    int c;
        
    while ((c = in.read()) != -1)
          out.write(c);
        in.close();
        out.close();
      }

    }


  7. How to use Properties
    Properties prop = new Properties();
    prop.setProperty(
    "abc""");
    Please note that, NullPointerException will be thrown: prop.setProperty(
    "abc"null); 
  8.  How to remove all '-' in the string
    System.out.println("str="+str.replaceAll("-"""));
  9.     How to trim a string
    String abc = " 300.00";
    System.out.println(
    "trim="+abc.trim());    
  10.  How to use StringTokenizer?
    String str = "'001','182-0-935722','',' 0.00',' 0.00','','20 Jul 2006','2','6','1820935722',''";
    StringTokenizer st 
    = new StringTokenizer(str.substring(str.indexOf("(")+1, str.indexOf(")")), ",");
    String[] strArray 
    = new String[11];
    System.out.println(st.countTokens());
    while (st.hasMoreElements()){
         String next 
    = st.nextToken();
         System.out.println(
    "next="+next);
          
    //remove ' '
         System.out.println("next="+next.substring(1, next.lastIndexOf("'")));      
    }




评论 / 个人网页 / 扔小纸条
* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 


 

分类小组论坛
杂谈 , 娱乐、八卦 , 文学、艺术 , 体育 , 旅游、同城 , 象牙塔 , 情感 , 时尚、生活 , 星座 , 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定