日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

java date类_Java的败笔-Date类

發布時間:2023/11/27 生活经验 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java date类_Java的败笔-Date类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

import java.sql.*;

import java.text.ParseException;

import java.text.SimpleDateFormat;

/**

* 日期增改查測試

*

* @author leizhimin 2009-11-9 11:15:46

*/

public class Test {

private static final String data_format = "yyyy-MM-dd kk:mm:ss";

private static final SimpleDateFormat sf = new SimpleDateFormat(data_format);

public static void main(String[] args) throws SQLException, ParseException {

Timestamp ts = new Timestamp(sf.parse("2009-12-10 13:33:15").getTime());

System.out.println(ts);

//????????????????test_insert1();

//????????????????test_insert2();

//????????????????test_insert3();

//????????????????test_update1();

//????????????????test_update2();

//????????????????test_query2();

}

public static void test_insert1() throws SQLException {

Connection conn = ConnTools.makeConnection();

Statement stmt = conn.createStatement();

String sql_1 = "insert into testdate(code,crdate) values ('x',CURRENT_TIMESTAMP)";

String sql_2 = "insert????into testdate(code,crdate) values ('y','2009-11-09 13:00:23')";

stmt.executeUpdate(sql_1);

stmt.executeUpdate(sql_2);

}

public static void test_insert2() throws SQLException {

Connection conn = ConnTools.makeConnection();

String sql = "insert into testdate(code,crdate) values ('z',?)";

PreparedStatement pstmt = conn.prepareStatement(sql);

pstmt.setTimestamp(1, new Timestamp(System.currentTimeMillis()));

pstmt.executeUpdate();

}

public static void test_insert3() throws SQLException {

Connection conn = ConnTools.makeConnection();

String sql = "insert into testdate(code,crdate) values ('w',?)";

PreparedStatement pstmt = conn.prepareStatement(sql);

pstmt.setString(1, "2009-11-09 13:00:23");

pstmt.executeUpdate();

}

public static void test_update1() throws SQLException {

Connection conn = ConnTools.makeConnection();

Statement stmt = conn.createStatement();

String sql = "update testdate set crdate = '2009-12-12 13:33:15' where code = 'z'";

stmt.executeUpdate(sql);

}

public static void test_update2() throws SQLException {

Connection conn = ConnTools.makeConnection();

String sql = "update testdate set crdate = ? where code = 'z'";

PreparedStatement pstmt = conn.prepareStatement(sql);

pstmt.setString(1, "2009-12-12 13:33:15");

pstmt.executeUpdate(sql);

}

//????????public static void test_update3() throws SQLException, ParseException {

//????????????????Connection conn = ConnTools.makeConnection();

//????????????????String sql = "update testdate set crdate = ? where code = 'z'";

//????????????????PreparedStatement pstmt = conn.prepareStatement(sql);

//????????????????pstmt.setTimestamp(1, new Timestamp(sf.parse("2009-11-09 13:00:23").getTime()));

//????????????????pstmt.executeUpdate(sql);

//????????}

public static void test_query1() throws SQLException {

Connection conn = ConnTools.makeConnection();

String sql = "select * from testdate where crdate > '2009-11-09 13:00:23' and crdate < '2009-11-10 13:00:23'";

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery(sql);

while (rs.next()) {

System.out.println(">>> id=" + rs.getLong("id") + "; code=" + rs.getString("code") + "; crdate=" + rs.getTimestamp("crdate"));

}

conn.close();

}

//????????public static void test_query2() throws SQLException, ParseException {

//????????????????Connection conn = ConnTools.makeConnection();

//????????????????String sql = "select * from testdate where crdate > ? and crdate < ?";

//????????????????PreparedStatement pstmt = conn.prepareStatement(sql);

????????????????pstmt.setString(1,"2009-11-09 13:00:23");

????????????????pstmt.setString(2,"2009-11-10 13:00:23");

//????????????????pstmt.setTimestamp(1,new Timestamp(sf.parse("2009-11-09 13:00:23").getTime()));

//????????????????pstmt.setTimestamp(2,new Timestamp(sf.parse("2009-11-10 13:00:23").getTime()));

//????????????????ResultSet rs = pstmt.executeQuery(sql);

//????????????????while (rs.next()) {

//????????????????????????System.out.println(">>> id=" + rs.getLong("id") + "; code=" + rs.getString("code") + "; crdate=" + rs.getTimestamp("crdate"));

//????????????????}

//????????????????conn.close();

//????????}

}

總結

以上是生活随笔為你收集整理的java date类_Java的败笔-Date类的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。