`
leifeng2
  • 浏览: 139324 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

解决时分秒不能写入Date类型字段中

 
阅读更多
CallableStatement cstmt = null;
cstmt=conn.prepareCall("{call write_vehicle_tempplate(?)}");
cstmt.setString(1,temp.elementText("HPHM"));  
cstmt.setTimestamp(2,getTimestamp(temp.elementText("DJRQ")));

 

public static Timestamp getTimestamp(String s){
	if(s==null||s.equals(""))
	{
		return null;
	}
	Timestamp timestamp=null;
	try 
	{
		if(s.length()>19)
		{
			s=s.substring(0,19);
		}
		
		SimpleDateFormat bartDateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		
		java.util.Date date = bartDateFormat.parse(s);
		
		timestamp= new Timestamp(date.getTime());

	} catch (ParseException e) 
	{
		e.printStackTrace();
	}
	
	return timestamp;	
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics