RUVIDEO
Поделитесь видео 🙏

Java JDBC Tutorial – Part 8: JDBC Database MetaData with MySQL

NEED TO LEARN JAVA? - 5 FREE JAVA VIDEO COURSES - CLICK HERE - https://goo.gl/7i95F8

---

View more videos on my "Java JDBC Tutorial" Playlist: http://goo.gl/crT4nS


Download Java Source Code: http://www.luv2code.com/?p=1039, Follow Me on Twitter: https://twitter.com/darbyluvs2code

Please SUBSCRIBE to this channel: https://www.youtube.com/user/luv2codetv?sub_confirmation=1

---

In this video tutorial we will learn how to retrieve JDBC database metadata with MySQL.

---

Transcript

Time - 00:00
Hi, this is Chad (Shod) with luv2code.com. Welcome back to another tutorial on Java JDBC. In this video we will learn how to use Database Metadata. For this tutorial we'll use the following table: employees. The table also has sample data for testing. I have a SQL script that'll create the table and add sample data for you. You can download it from the link below.

Time - 00:30
Database Metadata can give you information about your database. To get started with Database Metadata, you must first retrieve it from the connection object. This is accomplished by calling myCon.getMetadata, then we can call some methods on the object such as get product name and version, get JDBC driver information and so on.

Time - 00:48
There are a lot of methods available, you can go online and you can Google JDBC Metadata, there you'll find the actual JavaDoc for this class and you'll see all the methods that are available for it.

Time - 01:00
Let's switch over to Eclipse and see this in action. I have a very simple program called Metadata Basic Info. Let's walk through the code. The first thing we'll do in this application is we will get a connection to the database. Then using this database connection I can get the Metadata, it returns a special Database Metadata object. Now with this object I can retrieve information about the database, I can get the actual database product name, I could also get the product version and then from there I can move forward and get information about the JDBC driver. I can get the driver's name and also the driver version.

Time - 01:49
Let's go ahead and run this application. Once we run it, we see the output. It shows us the product name and the actual version, the actual JDBC driver name, MySQL Connector and also the JDBC driver version that we're using. This is very good information that we retrieved by accessing the Database Metadata.

Time - 02:13
We can also get information about the database schema. For example, we can get a list of all tables and also get a list of column names for each table along with our types.

Time - 02:29
All right so let's switch over to Eclipse and is this in action. I have a very simple program called Schema Info and let's walk through the code. In this main method I have some variables set up for catalog and all the various patterns. When you make calls to some of these Database Metadata methods, you can actually pass in patterns but for right now just keep it null just to keep it simple. Let's step through the code, the first thing we do is we get a connection to a database and we get the Metadata, we've seen all this before, then I like to get a list of tables so I say, "Database Metadata get tables" and I pass in those various patterns.

Time - 03:05
This will give me a list of all of the tables for this demo schema, it's going to return it as a ResultSet. This works like a normal ResultSet, I can just loop through this ResultSet and I can retrieve each table name and print it out. This will give me a list of all tables for this given schema.

Time - 03:24
I'd like to do a similar thing for columns. I'd like to get a list of all the columns for a given table. In this example, I want to get all of the columns for the employees table so I pass in employees here and I pass in any other patterns and so on and they're all set to null but here I want to get the employees table. It's going to return a list of columns for this employees table as a ResultSet and just like before I can just walk through this ResultSet and I can print out each column name. They also have methods for getting column types and so on but this is enough to get us started for now.

Time - 04:02
Now we can see the output of the application. The first thing at the top we get a list of tables and so in this example we only have one table and that's employees. Then we can also get a list of columns for this employees table and we have these six columns here: ID, last name, first name, email, department and salary.

[snip] See the "Transcript" tabs for details.

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Java JDBC Tutorial – Part 8: JDBC Database MetaData with MySQL», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.