请问一个setdate的问题

时间:2008-06-22 06:15:27   来源:论坛整理  作者:  编辑:chinaitzhe
PreparedStatement pstmt3=con.prepareStatement("insert Master(CompName,NoOfShares,PurRate,PurDate,CurrRate)"
"values (?,?,?,?,?)");
pstmt3.setString(1,"sina.com");
pstmt3.setInt(2,888);
pstmt3.setFloat(3,388);
pstmt3.setDate(4,这里的时间格式应该怎么写);
网友回复:
Java code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/



new java.sql.Date(date)

?
网友回复:不知道这样行不行...
to_date("2000-01-01","YYYY-MM-DD")
网友回复: pstmt3.setDate(4,这里的时间格式应该怎么写);

=========================
一般都用setString ,在内部实现
网友回复:在顶一下。希望有人解答
网友回复:
Java code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/





System.currentTimeMillis();??




网友回复:SimpleDateFormat sdf= new SimpleDateFormat("yyyy-mm-dd hh:MM:ss");
pstmt3.setDate( sdf.format(new Date()) );
这样就应该可以的,格式还可以随你设
网友回复:
Java code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/





Date date=new Date();

SimpleDateFormat format= new SimpleDateFormat("yyyy-mm-dd hh:MM:ss"); 

pstmt3.setDate( format.parse(date)); 





因为"pstmt3.setDate"知道你插入的是时间型的而不是以字符串的形式插入的,
所以可以用上面的方法.

6楼说的是以字串的形式插入.
网友回复:不好意思.
刚才没有写好就发上去了.
------------------------------
Java code





Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/





Date date=new Date();

        SimpleDateFormat format= new SimpleDateFormat("yyyy-mm-dd hh:MM:ss"); 

         String strdate=format.format(date);

         try {

            Date date1=format.parse(strdate);

            pstmt3.setDate(date1);

        } catch (ParseException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

    }







----------------------------
呵呵.
不好意思.
网友回复:SimpleDateFormat format= new SimpleDateFormat("yyyy-mm-dd hh:MM:ss");
标红的你就可以设置时间格式了.
关键字:请问,一个,setdate,问题,

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面