java格式化日期时间的函数
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
System.out.println(sdf.format(date));
SimpleDateFormat sdf2 = new SimpleDateFormat("MM");
System.out.println(sdf2.format(date));
Calendar c = Calendar.getInstance();
System.out.println(c.get(Calendar.MONTH)+1);
Date d=new Date(2010,5,12,13,24,30);
c.setTime(d);
System.out.println(c.get(Calendar.MONTH)+1);
--------------------------------------------------------------------
test=new JdbcTest();
String sql="{call proc_select3(?)};"; //调用语句
try {
CallableStatement proc=test.getConnection().prepareCall(sql);
proc.setString(1, "男");
//proc.execute();
ResultSet rs= proc.executeQuery();
while(rs.next())
{
System.out.print("id: "+rs.getInt("id"));
System.out.print(" userName :"+rs.getString("username"));
System.out.print(" age :"+rs.getInt("age"));
System.out.println(" sex :"+rs.getString("sex"));
Timestamp time=rs.getTimestamp("birthday");
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(">>>>>>>>>>>>>>>>>>"+sdf.format(time));
System.out.println(" birthday :"+rs.getDate("birthday"));
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
相关文档:
常常遇到数组排序的问题.比如我有一个Person类,它的实例对象存储在ArrayList数组中,现在要把ArrayList数组中的Person对象按照年龄排序.
其实这种情况经常遇到.
下面给出源代码:
1:Person.Java文件:-------------------------------
public class Person{
String name;
int age;
public Person(String name,int age){ ......
多线程程序
对于多线程的好处这就不多说了。但是,它同样也带来了某些新的麻烦。只要在设计程序时特别小心留意,克服这些麻烦并不算太困难。
(1)同步线程
许多线程在执行中必须考虑与其他线程之间共享数据或协调执行状态。这就 需要同步机制。在Java中每个对象都有一把锁与之对应。但Java不提供单独的lock和unlock操作。 ......
import java.awt.image. * ;
import com.sun.image.codec.jpeg. * ;
public class poiReadDoc {
Image img = null;
int width = 0,height =0;
String destFile = "";
public void readImg(String fileName) throws IOException{
File _fil ......
ArrayList是最常用的List实现类,内部是通过数组实现的,它允许对元素进行快速随机访问。数组的缺点是每个元素之间不能含有“空隙”,当数组大小不满足时需要增加存储能力,就要将已有数组数据复制到新的存储空间中。当从ArrayList的中间位置插入或者删除元素时,需要对数组进行复制、移动,代价比较高。因此, ......