AuditAllTenantUrls.java 1.5 KB

1234567891011121314151617181920212223
  1. import java.sql.*;
  2. public class AuditAllTenantUrls {
  3. public static void main(String[] a) throws Exception {
  4. Class.forName("com.mysql.cj.jdbc.Driver");
  5. Connection m = DriverManager.getConnection("jdbc:mysql://cq-cdb-8fjmemkb.sql.tencentcdb.com:27220/ylrz_saas?allowMultiQueries=true","root","Ylrz_1q2w3e4r5t6y");
  6. Statement st = m.createStatement();
  7. ResultSet rs = st.executeQuery("SELECT id, db_name, db_url, db_account, db_pwd, status FROM tenant_info ORDER BY id");
  8. while (rs.next()) {
  9. long id = rs.getLong(1); String dbName=rs.getString(2); String url=rs.getString(3);
  10. String user=rs.getString(4); String pwd=rs.getString(5); int status=rs.getInt(6);
  11. String host="?"; String db="?"; boolean has=false; String err=null;
  12. try {
  13. String body = url.substring(13); int slash=body.indexOf('/'); String hp=slash>=0?body.substring(0,slash):body;
  14. String rest=slash>=0?body.substring(slash+1):dbName; int q=rest.indexOf('?'); db=q>=0?rest.substring(0,q):rest;
  15. host=hp; Connection c = DriverManager.getConnection(url,user,pwd);
  16. ResultSet r2 = c.createStatement().executeQuery("SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='company_workflow_lobster' AND COLUMN_NAME='visible_company_ids'");
  17. r2.next(); has=r2.getInt(1)>0; c.close();
  18. } catch (Exception e) { err=e.getMessage(); }
  19. System.out.println("tenant="+id+" status="+status+" urlHost="+host+" db="+db+" has="+has+(err!=null?" ERR="+err:""));
  20. }
  21. m.close();
  22. }
  23. }