zoukankan      html  css  js  c++  java
  • JDBC_时间处理_Date_Time_Timestamp区别_随机日期生成

    import java.sql.Connection;

    import java.sql.DriverManager;

    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import java.sql.Timestamp;
    import java.util.Random;

    /**
    * 测试时间处理(java.sql.Date,Time,Timestamp)

    * @author Administrator
    */
    public class Demo007 {
    public static void main(String[] args) {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
    Class.forName("com.mysql.jdbc.Driver");
    conn = DriverManager.getConnection(
    "jdbc:mysql://localhost/testjdbc", "root", "");
    for (int i = 0; i < 100; i++) {
    ps = conn
    .prepareStatement("insert into t_user(username,pwd,regTime,lastLoginTime)values(?,?,?,?)");
    ps.setObject(1, "高斯" + i);
    ps.setObject(2, 666);
    int random = 1000 + new Random().nextInt(1000);
    java.sql.Date date1 = new java.sql.Date(
    System.currentTimeMillis() - random);
    Timestamp date2 = new Timestamp(System.currentTimeMillis()
    - random);
    ps.setDate(3, date1);
    ps.setTimestamp(4, date2);
    ps.execute();
    }
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    if (ps != null) {
    try {
    ps.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    if (conn != null) {
    try {
    conn.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }
    }
    }

  • 相关阅读:
    新购服务器流程
    nginx代理证书使用方法
    一键部署lnmp脚本
    mysql主从库配置读写分离以及备份
    Linux入门教程(更新完毕)
    Git 工作流程
    Git远程操作
    常用Git命令
    js数组去重
    Sublime Text设置快捷键让html文件在浏览器打开
  • 原文地址:https://www.cnblogs.com/qhcyp/p/10453455.html
Copyright © 2011-2022 走看看