Test.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package test;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.sunwin.metro.utils.MysqlUtil;
  4. import org.apache.flink.api.java.tuple.Tuple2;
  5. import java.sql.Connection;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. /**
  10. * @program: data_governance-no-cdc
  11. * @description:
  12. * @author: xuYJ
  13. * @create: 2022-03-24 16:00
  14. **/
  15. public class Test {
  16. public static void main(String[] args) throws InterruptedException, SQLException {
  17. Connection connection = MysqlUtil.getCon();
  18. PreparedStatement pStatement;
  19. while (true) {
  20. pStatement = connection.prepareStatement("SELECT * FROM t_data_rule ;");
  21. try {
  22. ResultSet results = pStatement.executeQuery();
  23. while (results.next()) {
  24. JSONObject jsonObject = new JSONObject();
  25. String ruleId = String.valueOf(results.getInt("id"));
  26. jsonObject.put("rule_id", ruleId);
  27. jsonObject.put("model", results.getString("target_name"));
  28. jsonObject.put("type", results.getString("equipment_type_code"));
  29. jsonObject.put("mes", results.getString("expr"));
  30. jsonObject.put("create_time", results.getDate("update_time"));
  31. jsonObject.put("flag", results.getInt("flag"));
  32. System.out.println("jsonObject = " + jsonObject);
  33. }
  34. } catch (SQLException e) {
  35. System.out.println("mysql连接异常1: " + e);
  36. e.printStackTrace();
  37. if (pStatement != null) {
  38. pStatement.close();
  39. }
  40. if (connection != null) {
  41. connection.close();
  42. }
  43. connection = MysqlUtil.getCon();
  44. }
  45. Thread.sleep(5000L);
  46. }
  47. }
  48. }