使用Java显示MySQL数据库中的所有表?
Sep 17, 2023 pm 08:37 PM我们将在这里看到如何使用 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中文网其他相关文章!
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前
By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
击败分裂小说需要多长时间?
3 周前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保护它?
3 周前
By DDD

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前
By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
击败分裂小说需要多长时间?
3 周前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保护它?
3 周前
By DDD

热门文章标签

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

在 Linux 中运行 MySQl(有/没有带有 phpmyadmin 的 podman 容器)

哪些流行的MySQL GUI工具(例如MySQL Workbench,PhpMyAdmin)是什么?
