一个字符串“2006-01-05”如何将它转换并存储到表中的一个DATE型字段中?

解决方案 »

  1.   

    oracle:String sql = "insert into table (date1) values (to_date('2006-01-05','yyyy-MM-dd'))";
      

  2.   

    不在sql里转化,该怎么转?就是直接的String型,变java.sql.date型,该怎样转才正确!多谢多谢!
      

  3.   

    public static java.sql.Date StringToDate(String param) {
    if(param==null) {
    return null;
    } else {
    java.util.Date date =null;
    try {
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
    date = sdf.parse(param);
    return new Date(date.getTime());
    }
    catch (ParseException ex) {
    //ex.printStackTrace();
    return null;
    }
    }
    }
      

  4.   

    public static final Date convertStringToDate(String aMask, String strDate)
    throws ParseException {
    SimpleDateFormat df = null;
    Date date = null;
    df = new SimpleDateFormat(aMask); try {
    date = df.parse(strDate);
    } catch (ParseException pe) {
    //log.error("ParseException: " + pe);
    throw new ParseException(pe.getMessage(), pe.getErrorOffset());
    } return (date);
    }
      

  5.   


    java.sql.Date d = java.sql.Date.valueOf("2006-01-24");
    java的api里有现成的,怎么就没人去看?