Date SDate=rs.getDate(1);
int year=SDate.getYear();
int month=SDate.getMonth();
int day=SDate.getDay();

解决方案 »

  1.   

    例如:rq为日期字段
    select to_char(rq,'yyyy') from tbl;
    select to_char(rq,'mm') from tbl;
    select to_char(rq,'dd') from tbl;
      

  2.   

    例如:rq为日期字段
    select to_char(rq,'yyyy'),to_char(rq,'mm'),to_char(rq,'dd') from tbl;
      

  3.   

    例如:rq为日期字段
    select to_char(rq,'yyyy'),to_char(rq,'mm'),to_char(rq,'dd') from tbl;
    这个好象是oracle数据库中的功能吧
      

  4.   

    java.util.Date SDate=rs.getDate(1);
    int year=SDate.getYear();
    int month=SDate.getMonth();
    int day=SDate.getDay();
     我试了,为什么不行????????!!!!!!     兄弟们帮帮我呀!!!!!!!!!!!!!!
      

  5.   

    从数据库出来的DATE应该是java.sql.date吧?
      

  6.   

    java.sql.Date SDate=rs.getDate("字段名");
    int year=SDate.getYear();
    int month=SDate.getMonth();
    int day=SDate.getDay();
      

  7.   

    Date SDate=rs.getDate(1);
    int year=SDate.getYear();
    int month=SDate.getMonth();
    int day=SDate.getDay();我这样试了,报错::::
    javax.servlet.ServletException: [Microsoft][ODBC SQL Server Driver]无效的描述符索引
    这是怎么回事,我该如何作呢????
    高手助我!!!!!!!!!!!!!!!!!!!!
      

  8.   

    你的sql语句呢?
    相关的代码帖出来看看
      

  9.   

    <%-- ==============以下是从数据库onePub 中取得数据==============--%>  
      <%
           String sql="select Title,Content,PictureURL,PubDate from OnePub  where ID="+idno+"and Category="+category;
       conn2=detail.getConn();
       stmt2=conn2.createStatement();
       ResultSet result2=stmt2.executeQuery(sql);

     //-------------------------fetching  the data-------------------------------------------- -
             
       
        if(result2.next()){
     java.util.Date pubdate=result.getDate(17);

     title=result2.getString("Title");
     content=result2.getString("Content");
                 picurl=result2.getString("PictureURL");
     //pubdate=result2.getDate(17);
     year=pubdate.getYear();
                 month=pubdate.getMonth();
                day=pubdate.getDay();

      %>
      

  10.   

    select 
        year(YourFieldOfDatetimeType),
        month(YourFieldOfDatetimeType),
        day(YourFieldOfDatetimeType)
    from ....
      

  11.   

    代码好乱呀
    java.util.Date pubdate=result.getDate(17);
    上面那句result也没定义,还有你要取的是不是PubDate的值
    那应该是在第四个呀.所以索引出错的.
    java.util.Date pubdate=result2.getDate(4);
      

  12.   

    1.用getString方法获得时间
    2.引用java.text.SimpleDateFormat定义SimpleDateFormat对象
    3.用SimpleDateFormat对象方法格式化日期
      

  13.   

    一个最粗笨的办法:用substring啊。呵呵
    yeah = time.substring(x,y);
    month= time.substring(n,m);
    .....
      

  14.   

     pubdate=result.getDate(3);
       pubyear=pubdate.getYear()+1900;
       pubmonth=pubdate.getMonth()+1;
       pubday=pubdate.getDate();
     enddate=result.getDate(4);
       endyear=enddate.getYear()+1900;
       endmonth=enddate.getMonth()+1;
       endday=enddate.getDate();
    我这样搞定了!! 谢谢各位兄弟!!!!!!!!!!!!!!