直接造数据插入数据库:
package com.chorany;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Random;
/**
* @Author: chorany
* @Date: 2022/1/17 21:42
* @Description:
* @Version:
*/
public class ChoranyTest {
public static void main(String[] args) {
ArrayList<String> realTimeS = new ArrayList<>();
realTimeS.add("REALTIME");
realTimeS.add("OFFLINE");
ArrayList<String> amountTypes = new ArrayList<>();
amountTypes.add("REPAY");
amountTypes.add("LOAN");
amountTypes.add("PRIN_BALANCE");
for (int i = 0; i < 10; i++) {
int id = i+10000;
String realTime = realTimeS.get(new Random().nextInt(2));
Timestamp timestamp = new Timestamp(1577808000000L+new Random().nextInt(645408000));
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
String dateTime = simpleDateFormat.format(timestamp);
String date = simpleDateFormat1.format(timestamp);
int amount = new Random().nextInt(10000);
String amountType = amountTypes.get(new Random().nextInt(3));
testInsert(id,realTime,date,dateTime,"all",amount,amountType);
}
}
public static void testInsert(int id,String realTime,String date,String dateTime,String channel,int amount,String amountType){
Connection conn;
PreparedStatement stmt;
String driver = "com.mysql.cj.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC";
String user = "root";
String password = "root";
String sql = "INSERT INTO alm_mbloan_dashbord values(?,?,?,?,?,?,?,?,?,?)";
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, user, password);
stmt = conn.prepareStatement(sql);
stmt.setInt(1,id);
stmt.setTimestamp(2,new Timestamp(System.currentTimeMillis()));
stmt.setTimestamp(3,new Timestamp(System.currentTimeMillis()));
stmt.setString(4, realTime);
stmt.setString(5,date);
stmt.setString(6,dateTime);
stmt.setString(7,channel);
stmt.setInt(8,amount);
stmt.setString(9,amountType);
stmt.setInt(10,0);
stmt.executeUpdate();
conn.commit();
stmt.close();
conn.close();
} catch (ClassNotFoundException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}