我們將在這裡看到如何使用 Java 顯示 MySQL 資料庫中的所有資料表。您可以使用 MySQL 中的 show 指令來取得 MySQL 資料庫中的所有資料表。
假設我們的資料庫是「test」。 Java程式碼如下,顯示資料庫「test」內的所有表名。
Java程式碼如下。這裡,MySQL 和Java 之間建立了連線-
import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import com.mysql.jdbc.Connection; import com.mysql.jdbc.DatabaseMetaData; public class GetAllTables { public static void main(String[] args) throws SQLException { Connection conn = null; try { try { Class.forName("com.mysql.jdbc.Driver"); } catch (Exception e) { System.out.println(e); } conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/test", "Manish", "123456"); System.out.println("Connection is created succcessfully:"); } catch (Exception e) { System.out.println(e); } ResultSet rs = null; DatabaseMetaData meta = (DatabaseMetaData) conn.getMetaData(); rs = meta.getTables(null, null, null, new String[] { "TABLE" }); int count = 0; System.out.println("All table names are in test database:"); while (rs.next()) { String tblName = rs.getString("TABLE_NAME"); System.out.println(tblName); count++; } System.out.println(count + " Rows in set "); } }
以下是顯示資料庫測試中所有資料表的輸出-
Wed Dec 12 14:55:28 IST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL = false, or set useSSL = true and provide truststore for server certificate verification. Connection is created succcessfully: All table names are in test database: add30minutesdemo addcolumn addoneday agecalculatesdemo aliasdemo allcharacterbeforespace allownulldemo appendingdatademo autoincrementdemo betweendatedemo bigintandintdemo bigintdemo bookdatedemo changecolumnpositiondemo changeenginetabledemo charsetdemo concatenatetwocolumnsdemo constraintdemo cumulativesumdemo currentdatetimedemo customers dateasstringdemo dateformatdemo dateinsertdemo datesofoneweek datetimedemo dayofweekdemo decimaltointdemo decrementdemo defaultdemo deleteallfromtable deletemanyrows destination differencetimestamp distinctdemo employee employeedesignation findlowercasevalue generatingnumbersdemo gmailsignin groupbytwofieldsdemo groupmonthandyeardemo highestidorderby highestnumberdemo ifnulldemo increasevarchardemo insert insertignoredemo insertwithmultipleandsigle int11demo intvsintanythingdemo lasttwocharacters likebinarydemo likedemo maxlengthfunctiondemo moviecollectiondemo myisamtoinnodbdemo newtableduplicate notequalsdemo nowandcurdatedemo nthrecorddemo nullandemptydemo orderbycharacterlength orderbynullfirstdemo orderindemo originaltable parsedatedemo passinganarraydemo persons prependstringoncolumnname pricedemo queryresultdemo replacedemo rowexistdemo rowpositiondemo rowwithsamevalue safedeletedemo searchtextdemo selectdataonyearandmonthdemo selectdistincttwocolumns selectdomainnameonly sha256demo skiplasttenrecords sortcolumnzeroatlastdemo storedproctable stringreplacedemo stringtodate student studentdemo studentmodifytabledemo studenttable subtract3hours temporarycolumnwithvaluedemo timetosecond timetoseconddemo toggledemo toogledemo truncatetabledemo updatealldemo updatevalueincrementally wheredemo wholewordmatchdemo zipcodepadwithzerodemo 103 Rows in set
要進行交叉檢查,請使用MySQL show 指令顯示資料庫「test ”內的所有表。查詢如下 -
mysql> use test; Database changed mysql> show tables;
以下是輸出 -
+------------------------------+ | Tables_in_test | +------------------------------+ | add30minutesdemo | | addcolumn | | addoneday | | agecalculatesdemo | | aliasdemo | | allcharacterbeforespace | | allownulldemo | | appendingdatademo | | autoincrementdemo | | betweendatedemo | | bigintandintdemo | | bigintdemo | | bookdatedemo | | changecolumnpositiondemo | | changeenginetabledemo | | charsetdemo | | concatenatetwocolumnsdemo | | constraintdemo | | cumulativesumdemo | | currentdatetimedemo | | customers | | dateasstringdemo | | dateformatdemo | | dateinsertdemo | | datesofoneweek | | datetimedemo | | dayofweekdemo | | decimaltointdemo | | decrementdemo | | defaultdemo | | deleteallfromtable | | deletemanyrows | | destination | | differencetimestamp | | distinctdemo | | employee | | employeedesignation | | findlowercasevalue | | generatingnumbersdemo | | gmailsignin | | groupbytwofieldsdemo | | groupmonthandyeardemo | | highestidorderby | | highestnumberdemo | | ifnulldemo | | increasevarchardemo | | insert | | insertignoredemo | | insertwithmultipleandsigle | | int11demo | | intvsintanythingdemo | | lasttwocharacters | | likebinarydemo | | likedemo | | maxlengthfunctiondemo | | moviecollectiondemo | | myisamtoinnodbdemo | | newtableduplicate | | notequalsdemo | | nowandcurdatedemo | | nthrecorddemo | | nullandemptydemo | | orderbycharacterlength | | orderbynullfirstdemo | | orderindemo | | originaltable | | parsedatedemo | | passinganarraydemo | | persons | | prependstringoncolumnname | | pricedemo | | queryresultdemo | | replacedemo | | rowexistdemo | | rowpositiondemo | | rowwithsamevalue | | safedeletedemo | | searchtextdemo | | selectdataonyearandmonthdemo | | selectdistincttwocolumns | | selectdomainnameonly | | sha256demo | | skiplasttenrecords | | sortcolumnzeroatlastdemo | | storedproctable | | stringreplacedemo | | stringtodate | | student | | studentdemo | | studentmodifytabledemo | | studenttable | | subtract3hours | | temporarycolumnwithvaluedemo | | timetosecond | | timetoseconddemo | | toggledemo | | toogledemo | | truncatetabledemo | | updatealldemo | | updatevalueincrementally | | wheredemo | | wholewordmatchdemo | | zipcodepadwithzerodemo | +------------------------------+ 103 rows in set (0.01 sec)
正如您在上面看到的,它們都給出了相同的結果。
以上是使用Java顯示MySQL資料庫中的所有表格?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本文探討了Docker中的優化MySQL內存使用量。 它討論了監視技術(Docker統計,性能架構,外部工具)和配置策略。 其中包括Docker內存限制,交換和cgroups

本文介紹了MySQL的“無法打開共享庫”錯誤。 該問題源於MySQL無法找到必要的共享庫(.SO/.DLL文件)。解決方案涉及通過系統軟件包M驗證庫安裝

本文討論了使用MySQL的Alter Table語句修改表,包括添加/刪除列,重命名表/列以及更改列數據類型。

本文比較使用/不使用PhpMyAdmin的Podman容器直接在Linux上安裝MySQL。 它詳細介紹了每種方法的安裝步驟,強調了Podman在孤立,可移植性和可重複性方面的優勢,還

本文提供了SQLite的全面概述,SQLite是一個獨立的,無服務器的關係數據庫。 它詳細介紹了SQLite的優勢(簡單,可移植性,易用性)和缺點(並發限制,可伸縮性挑戰)。 c

本指南展示了使用自製在MacOS上安裝和管理多個MySQL版本。 它強調使用自製裝置隔離安裝,以防止衝突。 本文詳細詳細介紹了安裝,起始/停止服務和最佳PRA

文章討論了為MySQL配置SSL/TLS加密,包括證書生成和驗證。主要問題是使用自簽名證書的安全含義。[角色計數:159]

文章討論了流行的MySQL GUI工具,例如MySQL Workbench和PhpMyAdmin,比較了它們對初學者和高級用戶的功能和適合性。[159個字符]


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

Dreamweaver CS6
視覺化網頁開發工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),