转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> ORACLE >> 正文
从oracle 数据库读取日期时间,并在网页上打印万年历         ★★★★

从oracle 数据库读取日期时间,并在网页上打印万年历

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1850 更新时间:2009/4/22 22:03:47

在core Java 那本书里,在讲类之前就将了一个打印一个月份中每天是星期几的万年历程序.最近写程序的时候终于要用到了.我花费了半天时间终于弄明白了GregorianCalendar类,并且通过网络抓取oracle数据的时间,然后显示在JSP 网页上.

运行效果如下:

首先要在J2se里面写出万年历程序,作为练习:

1)星期日Calendar.SUNDAY =1  星期日为1,那么星期几就+1为以此类推!

打印月历的程序:

package moonsoft.j2se.testYueli;

import java.util.*;

 

 

public class TestYueli

{

  public static void main(String [] args)

  {  //建立一个GregorianCalendar 对象

    GregorianCalendar d=new GregorianCalendar();

    //获得系统默认的日期的月份和日期所在的月第几天

    int month=d.get(Calendar.MONTH);

    int day=d.get(Calendar.DAY_OF_MONTH);

    //把d设置为当月第一天

    d.set(Calendar.DAY_OF_MONTH, 1);

    //获得第一天的是一星期的第几天

int weekday=d.get(Calendar.DAY_OF_WEEK);

 

 

    System.out.println("SUN MON TUE WED THU FRI SAT");

    for(int i=Calendar.SUNDAY; i<weekday; i++)

    System.out.print("   ");

    //System.out.print(monthday);

    do

    {

      int days=d.get(Calendar.DAY_OF_MONTH);

      if(days<10)

      System.out.print(" ");

      System.out.print(days);

      if(days==day)

      System.out.print("*");

      else

      System.out.print(" ");

      if(weekday==Calendar.SATURDAY)

      System.out.println();

      d.add(Calendar.DAY_OF_MONTH, 1);

      weekday=d.get(Calendar.DAY_OF_WEEK);

   

    }while(d.get(Calendar.MONTH)==month);

     } }

2)注意GregorianCalendar calendar=new(year, month-1,year);

month-1! 在Calendar 0代表一月!!!

然后再写oracle抓取到JSP 页面的程序:

<%@ page contentType="text/html;charset=Big5"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%>
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=Big5">
    <title>社團活動</title>
    <style type="text/css">
<!--
.style1 {color: #FFFFFF}
-->
    </style>
  </head>
  <%
  request.setCharacterEncoding("big5");
  String name=(String)session.getAttribute("name");
  String queryDate=" select to_char(systimestamp, ''''YYYY-MM-DD HH24:MM:SS'''') from dual ";
  int  day=1;
  int month=3;
  int year=2005;
  Connection conn=null;
 
  try{
  Context ctx=new InitialContext();
  DataSource ds=(DataSource)ctx.lookup("jdbc/asdbCoreDS");
  conn=ds.getConnection();
  PreparedStatement ps=conn.prepareStatement(queryDate);
  ResultSet rs=ps.executeQuery();
  while(rs.next()){
  String date=rs.getString(1);
  year=Integer.parseInt(date.substring(0,4));
  month=Integer.parseInt(date.substring(5,7));
  day=Integer.parseInt(date.substring(8,10));
  out.println(year+"年"+month+"月");
  }
  }
  catch(Exception e1){e1.printStackTrace();}
  finally{conn.close();}
 
  %>
 
  <body>
  <table width="100%"  border="1" cellspacing="1" cellpadding="1">
    <tr bgcolor="#0099FF">
      <th scope="col"><span class="style1">SUN</span></th>
      <th scope="col"><span class="style1">MON</span></th>
      <th scope="col"><span class="style1">TUE</span></th>
      <th scope="col"><span class="style1">WED</span></th>
      <th scope="col"><span class="style1">THU</span></th>
      <th scope="col"><span class="style1">FRI</span></th>
      <th scope="col"><span class="style1">SAT</span></th>
    </tr> <tr>
    <%
    GregorianCalendar d=new GregorianCalendar(year, month-1 , day);
   
    int monthDay=d.get(Calendar.DAY_OF_MONTH);
    int monthNumber=d.get(Calendar.MONTH);
   
    d.set(Calendar.DAY_OF_MONTH, 1);
    int weekDay=d.get(Calendar.DAY_OF_WEEK);
    for(int i=Calendar.SUNDAY; i<weekDay; i++)
    {%><td height="45">&nbsp;</td><%}
    do{
    int monthDays=d.get(Calendar.DAY_OF_MONTH);
    %><td height="45"><%=mo

[1] [2]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台