这篇文章主要为大家详细介绍了MySQL与Java的时间类型的简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小玲来看看吧!
MySql的时间类型有 Java中与之对应的时间类型代码如下:
public void testDate()throws SQLException
{
IDBFace DBFace =DBFactory.createMySqlFace();
DBFace.connect();
//清空表
String strDelete ="delete from time_table";
DBFace.update(strDelete);
//添加
String strInsert ="insert into time_table(CreateDate) values(20070409)";
DBFace.update(strInsert);
//获取
String strSelect ="select * from time_table";
ResultSet rsBuffer =DBFace.select(strSelect);
while(rsBuffer.next())
{
Date dtDate =rsBuffer.getDate("CreateDate");
System.out.println(dtDate.toString());
}
DBFace.close();
}
代码如下:
public void testDateTime() throws SQLException
{
IDBFace DBFace =DBFactory.createMySqlFace();
DBFace.connect();
//清空表
String strDelete ="delete from time_table";
DBFace.update(strDelete);
//添加
String strInsert ="insert into time_table(CreateDateTime) values(20070409132013)";
DBFace.update(strInsert);
//获取
String strSelect ="select * from time_table";
ResultSet rsBuffer =DBFace.select(strSelect);
while(rsBuffer.next())
{
Timestamp tsBuffer =rsBuffer.getTimestamp("CreateDateTime");
System.out.println(tsBuffer.toString());
}
DBFace.close();
}
代码如下:
public void testTime() throws SQLException
{
IDBFace DBFace =DBFactory.createMySqlFace();
DBFace.connect();
//清空表
String strDelete ="delete from time_table";
DBFace.update(strDelete);
//添加
String strInsert ="insert into time_table(CreateTime) values(131211)";
DBFace.update(strInsert);
//获取
String strSelect ="select * from time_table";
ResultSet rsBuffer =DBFace.select(strSelect);
while(rsBuffer.next())
{
Time tmBuffer =rsBuffer.getTime("CreateTime");
System.out.println(tmBuffer.toString());
}
DBFace.close();
}
代码如下:
public void testYear() throws SQLException
{
IDBFace DBFace =DBFactory.createMySqlFace();
DBFace.connect();
//清空表
String strDelete ="delete from time_table";
DBFace.update(strDelete);
//添加
String strInsert ="insert into time_table(CreateYear) values(2007)";
DBFace.update(strInsert);
//获取
String strSelect ="select * from time_table";
ResultSet rsBuffer =DBFace.select(strSelect);
while(rsBuffer.next())
{
Date dtBuffer =rsBuffer.getDate("CreateYear");
System.out.println(dtBuffer.getYear()+1900);
}
DBFace.close();
}
本文来自:http://www.q1010.com/173/15241-0.html
注:关于MySQL与Java的时间类型的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:时间类型
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。