如何在實現 JDBC - MySQL CONNECTION 查詢時顯示儲存引擎?


使用 SELECT ENGINE 顯示儲存引擎名稱。我們首先建立一個表 -

mysql> create table DemoTable
   -> (
   -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> Name varchar(20),
   -> Age int,
   -> CountryName varchar(20)
   -> );
Query OK, 0 rows affected (0.63 sec)

下面是使用 JDBC 獲取儲存引擎的 Java 程式碼 -

示例

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class GetTheStorageEngine {
   public static void main(String[] args) {
      String hostURL = "jdbc:mysql://:3306/web?useSSL=false";
      Connection con = null;
      Statement stmt = null;
      try {
         con = DriverManager.getConnection(hostURL, "root", "123456");
         stmt = con.createStatement();
         String yourTablename = "DemoTable";
         ResultSet resultSet = stmt.executeQuery("select engine from information_schema.tables where          table_name='" + yourTablename + "';");
         resultSet.next();
         System.out.println("The engine is=" + resultSet.getString(1));
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }
}

輸出

將生成以下輸出 -

The storage engine is=InnoDB

更新於: 2019 年 12 月 17 日

112 次瀏覽

開啟您的 職業生涯

完成課程認證

開始
廣告