简体   繁体   中英

resultSet.getString(“TABLE_CAT”) - what is TABLE_CAT?

The code below works properly and shows me a list of databases in my database. In the code given below, What is TABLE_CAT and Why is it there ?

import java.sql.*;
public class Database{
public static void main(String [] args) {
Connection con = null;
try {
  con = DriverManager.getConnection("jdbc:mysql://localhost:3306","cowboy","123456");
  DatabaseMetaData meta = con.getMetaData();
  ResultSet res = meta.getCatalogs();
  System.out.println("List of databases: "); 
  while (res.next()) {
     System.out.println("   " + res.getString("TABLE_CAT"));
  }

  res.close();
  con.close();
} catch (SQLException e) {
  System.err.println("SQLException: " + e.getMessage());
}
}
}

TABLE_CAT is the name of the column in your resutSet. As you are iterating over your result set row by row, using res.getString("TABLE_CAT")) allows you to extract the value from that column in the current result row. As meta.getCatalogs() returns catalog names available in a database, the catalog name is then stored under a column called TABLE_CAT.

This should make more sense to you now.

TABLE CATEGORY ??

It's a simple key that can be used to extract values from the resultSet of the meta-data

You can use the ResultSetMetaData (that can be obtained from the ResultSet ) to list all the column names available within the ResultSet

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM