当前位置: 技术问答>java相关
如何将时间加入数据库?
来源: 互联网 发布时间:2015-04-09
本文导语: 如何将时间加入数据库?最好给例程 | import java.sql.Date ; import java.sql.Time ; PreparedStatement ps = conn.prepareStatement("INSERT INTO clientcount(userid,ip,onlinetime,date,time) VALUES(?,?,?,?,?)"); int i=0; ...
如何将时间加入数据库?最好给例程
|
import java.sql.Date ;
import java.sql.Time ;
PreparedStatement ps = conn.prepareStatement("INSERT INTO clientcount(userid,ip,onlinetime,date,time) VALUES(?,?,?,?,?)");
int i=0;
ClientCounter clientCounter = (ClientCounter) vecCounters.elementAt (0);
ps.setString(1,clientCounter.getUserName ());
ps.setString (2,clientCounter.getIP ());
ps.setLong (3,clientCounter.getSecond ());
ps.setDate (4,new Date(clientCounter.getTime ()));
ps.setTime(5,new Time(clientCounter.getTime ()));
ps.execute ();
import java.sql.Time ;
PreparedStatement ps = conn.prepareStatement("INSERT INTO clientcount(userid,ip,onlinetime,date,time) VALUES(?,?,?,?,?)");
int i=0;
ClientCounter clientCounter = (ClientCounter) vecCounters.elementAt (0);
ps.setString(1,clientCounter.getUserName ());
ps.setString (2,clientCounter.getIP ());
ps.setLong (3,clientCounter.getSecond ());
ps.setDate (4,new Date(clientCounter.getTime ()));
ps.setTime(5,new Time(clientCounter.getTime ()));
ps.execute ();
|
String timeValue="{t '00:00:00'}";
String dateValue="{d '2002-6-1'}";
String dateTimeValue="{ts '2002-6-1 00:00:00'}";
PreparedStatement ps = conn.prepareStatement("INSERT INTO table(timeField,dateField,dateTimeField) VALUES("+timeValue+","+dateValue+","+dateTimeValue+")");
String dateValue="{d '2002-6-1'}";
String dateTimeValue="{ts '2002-6-1 00:00:00'}";
PreparedStatement ps = conn.prepareStatement("INSERT INTO table(timeField,dateField,dateTimeField) VALUES("+timeValue+","+dateValue+","+dateTimeValue+")");
|
String Str_Date="2002/3/2 0:0:0";
Date d=new Date(Str_Date);
Date d=new Date(Str_Date);