• mysql 提取 schema,table,column names


    参考:

    https://dzone.com/articles/how-use-linkedin-market-your

    表空间信息

    https://coderanch.com/t/300498/databases/Java-find-List-tablespaces-database

    getCatalogs()

    存储过程

    https://dev.mysql.com/doc/refman/5.7/en/routines-table.html

    注释

    https://dev.mysql.com/doc/refman/8.0/en/columns-table.html

    外键

    https://dev.mysql.com/doc/refman/5.5/en/constraint-foreign-key.html

     package com.dataconnect.test.util;
    import java.sql.Connection;
    import java.sql.DatabaseMetaData;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    public class SchemaDetailsTest {
       private static Logger log = LoggerFactory
           .getLogger(SchemaDetailsTest.class);
       public static void main(String args[]) throws Exception {
         String databaseName = "myDbName";
         String userName = "username";
         String password = "password";
         String mySQLPort = "3306";
         String hostUrl = "127.0.0.1";
         // Setup the connection with the DB
         Class.forName("com.mysql.jdbc.Driver");
         Connection conn = DriverManager.getConnection("jdbc:mysql://" + hostUrl
             + ":" + mySQLPort, userName, password);
         // --- LISTING DATABASE SCHEMA NAMES ---
         ResultSet resultSet = conn.getMetaData().getCatalogs();
         while (resultSet.next()) {
           log.info("Schema Name = " + resultSet.getString("TABLE_CAT"));
         }
         resultSet.close();
         // --- LISTING DATABASE TABLE NAMES ---
         String[] types = { "TABLE" };
         resultSet = conn.getMetaData()
             .getTables(databaseName, null, "%", types);
         String tableName = "";
         while (resultSet.next()) {
           tableName = resultSet.getString(3);
           log.info("Table Name = " + tableName);
         }
         resultSet.close();
         // --- LISTING DATABASE COLUMN NAMES ---
         DatabaseMetaData meta = conn.getMetaData();
         resultSet = meta.getColumns(databaseName, null, tableName, "%");
         while (resultSet.next()) {
           log.info("Column Name of table " + tableName + " = "
               + resultSet.getString(4));
         }
       }
    }
  • 相关阅读:
    websocket初体验(能传文字和图片)
    展开折叠效果 height未知 transition无效
    微信小程序自定义键盘
    微信小程序 selectComponent 值为null
    css 斜线 animation
    【转】怎样在ubuntu12.04下创建一个启动器
    以ontouch为例说明android事件发送机制
    谈谈移动应用设计——从一个普通开发者的角度
    Launch error: Failed to connect to remote VM. Connection refused.的解决办法
    Beyond compare代码比较工具。
  • 原文地址:https://www.cnblogs.com/lvlin241/p/10414969.html
Copyright © 2020-2023  润新知