pstmt.setDate(2, new java.sql.Date(date2.getTime()));
第三:
其实向mysql数据库里插入时间字段也是很容易的,只要设置为java.util.Date类型后,以Hibernate的Pojo类对象为例,pojo.set(new java.util.Date());就可用了。
以下附录在网上找到的相关资料:
Mysql 与 java 的时间类型
MySql的时间类型有 Java中与之对应的时间类型
date java.sql.Date
Datetime java.sql.Timestamp
Timestamp java.sql.Timestamp
Time java.sql.Time
Year java.sql.Date
于是便通过以下方式去实现:
Date date = new Date();//获得系统时间.
String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);//将时间格式转换成符合Timestamp要求的格式.
Timestamp goodsC_date = Timestamp.valueOf(nowTime);//把时间转换
java.util.Date 是java.sql.Date的父类
1.包:
package beanpackage;
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/webkaifa/)/**
*
* @author lucifer
*/
public class SystemProperties {
public String getRuntimeEnvironmentVersion(){
return System.getProperty("java.version");
}
public String getRuntimeEnvironmentVendor(){
return System.getProperty("java.vendor");
}
public String getVmVersion(){
return System.getProperty("java.vm.version");
}
public String getVmVendor(){
return System.getProperty("java.vm.vendor");
}
public String getVmName(){
return System.getProperty("java.vm.name");
}
public String getVmSpecVersion(){
return System.getProperty("java.vm.specification.version");
}
public String getVmSpecVendor(){
return System.getProperty("java.vm.specification.vendor");
}
public String getVmSpecName(){
return System.getProperty("java.vm.specification.name");
}
public String getRteSpecName(){
return System.getProperty("java.specification.name");
}
public String getRteSpecVersion(){
return System.getProperty("java.specification.version");
}
public String getRteSpecVendor(){
return System.getProperty("java.specification.vendor");
}
public String getOperatingSystemName(){
return System.getProperty("os.name");
}
public String getOperatingSystemVersion(){
return System.getProperty("os.version");
}
public String getOperatingSystemArchitecture(){
return System.getProperty("os.arch");
}
}
2.JSP代码:
%--
Document : usebean
Created on : 2009-10-3, 13:06:24
Author : lucifer
--%
%@page contentType="text/html" pageEncoding="UTF-8"%
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
jsp:useBean id="properties" class="beanpackage.SystemProperties"/
html
head
meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
titleJSP Page/title
/head
body
Operating System Name:
jsp:getProperty name="properties" property="operatingSystemName"/
br
Operating System Version:
jsp:getProperty name="properties" property="operatingSystemVersion"/
br
Operating System Architecture:
jsp:getProperty name="properties" property="operatingSystemArchitecture"/
br
br
Runtime Environment Version(JDK version):
jsp:getProperty name="properties" property="runtimeEnvironmentVersion"/
br
Runtime Environment Vendor(JDK vendor):
jsp:getProperty name="properties" property="runtimeEnvironmentVendor"/
br
br
VM Version:
jsp:getProperty name="properties" property="vmVersion"/
br
VM Vendor:
jsp:getProperty name="properties" property="vmVendor"/
br
VM Name:
jsp:getProperty name="properties" property="vmName"/
br
br
RTE Specification Version:
jsp:getProperty name="properties" property="rteSpecVersion"/
br
RTE Specification Vendor:
jsp:getProperty name="properties" property="rteSpecVendor"/
br
RTE Specification Name:
jsp:getProperty name="properties" property="rteSpecName"/
br
br
VM Specification Name:
jsp:getProperty name="properties" property="vmSpecName"/
br
VM Specification Version:
jsp:getProperty name="properties" property="vmSpecVersion"/
br
VM Specification Vendor:
jsp:getProperty name="properties" property="vmSpecVendor"/
/body
/html
3.输出:
Operating System Name: Windows Vista
Operating System Version: 6.0
Operating System Architecture: x86
Runtime Environment Version(JDK version): 1.6.0_16
Runtime Environment Vendor(JDK vendor): Sun Microsystems Inc.
VM Version: 14.2-b01
VM Vendor: Sun Microsystems Inc.
VM Name: Java HotSpot(TM) Client VM
RTE Specification Version: 1.6
RTE Specification Vendor: Sun Microsystems Inc.
RTE Specification Name: Java Platform API Specification
VM Specification Name: Java Virtual Machine Specification
VM Specification Version: 1.0
VM Specification Vendor: Sun Microsystems Inc.