12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package test;
- import com.alibaba.fastjson.JSONObject;
- import com.sunwin.metro.utils.MysqlUtil;
- import org.apache.flink.api.java.tuple.Tuple2;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- /**
- * @program: data_governance-no-cdc
- * @description:
- * @author: xuYJ
- * @create: 2022-03-24 16:00
- **/
- public class Test {
- public static void main(String[] args) throws InterruptedException, SQLException {
- Connection connection = MysqlUtil.getCon();
- PreparedStatement pStatement;
- while (true) {
- pStatement = connection.prepareStatement("SELECT * FROM t_data_rule ;");
- try {
- ResultSet results = pStatement.executeQuery();
- while (results.next()) {
- JSONObject jsonObject = new JSONObject();
- String ruleId = String.valueOf(results.getInt("id"));
- jsonObject.put("rule_id", ruleId);
- jsonObject.put("model", results.getString("target_name"));
- jsonObject.put("type", results.getString("equipment_type_code"));
- jsonObject.put("mes", results.getString("expr"));
- jsonObject.put("create_time", results.getDate("update_time"));
- jsonObject.put("flag", results.getInt("flag"));
- System.out.println("jsonObject = " + jsonObject);
- }
- } catch (SQLException e) {
- System.out.println("mysql连接异常1: " + e);
- e.printStackTrace();
- if (pStatement != null) {
- pStatement.close();
- }
- if (connection != null) {
- connection.close();
- }
- connection = MysqlUtil.getCon();
- }
- Thread.sleep(5000L);
- }
- }
- }
|