Typically, data about data is called metadata.DatabaseMetaDataThe interface provides some methods to get information about the database you are connected to, such as database name, database driver version, maximum column length, etc...
Here are some methodsDatabaseMetaDataClass.
Method | Description|
---|---|
##getDriverName() | Retrieve the name of the current JDBC driver|
getDriverVersion() | Retrieve the version of the current JDBC drivertd> |
getUserName() | Retrieve the user name.|
getDatabaseProductName() | Retrieve the name of the current database.|
getDatabaseProductVersion() | Retrieve the version of the current database.|
getNumericFunctions() | Retrieves a list of numeric functions available for this database.|
getStringFunctions() | Retrieves a list of numeric functions available for this database.td> |
getSystemFunctions() | Retrieve the list of system functions available for this database.|
getTimeDateFunctions() | Retrieves a list of time and date functions available for this database.|
getURL() | Retrieve the URL of the current database.|
supportsSavepoints()Verify whether the current database supports savepoints | |
supportsStoredProcedures () | Verify the weather support stored procedure for the current database.|
supportsTransactions() | Verify whether the current database supports transactions.
import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; public class DatabaseMetadataExample { public static void main(String args[])throws Exception { //Getting the connection String mysqlUrl = "jdbc:mysql://localhost/sampleDB"; Connection con = DriverManager.getConnection(mysqlUrl, "root", "password"); System.out.println("Connection established......"); //Creating the DatabaseMetaData object DatabaseMetaData dbMetadata = con.getMetaData(); //invoke the supportsBatchUpdates() method. boolean bool = dbMetadata.supportsBatchUpdates(); if(bool) { System.out.println("Underlying database supports batch updates"); } else { System.out.println("Underlying database doesnt supports batch updates"); } //Retrieving the driver name System.out.println(dbMetadata.getDriverName()); //Retrieving the driver version System.out.println(dbMetadata.getDriverVersion()); //Retrieving the user name System.out.println(dbMetadata.getUserName()); //Retrieving the URL System.out.println(dbMetadata.getURL()); //Retrieving the list of numeric functions System.out.println("Numeric functions: "+dbMetadata.getNumericFunctions()); System.out.println(""); //Retrieving the list of String functions System.out.println("String functions: "+dbMetadata.getStringFunctions()); System.out.println(""); //Retrieving the list of system functions System.out.println("System functions: "+dbMetadata.getSystemFunctions()); System.out.println(""); //Retrieving the list of time and date functions System.out.println("Time and Date funtions: "+dbMetadata.getTimeDateFunctions()); } }
Connection established...... Underlying database supports batch updates MySQL-AB JDBC Driver mysql-connector-java-5.1.12 ( Revision: ${bzr.revision-id} ) root@localhost jdbc:mysql://localhost/sampleDB Numeric functions: ABS,ACOS,ASIN,ATAN,ATAN2,BIT_COUNT,CEILING,COS,COT,DEGREES,EXP,FLOOR,LOG,LOG10,MAX ,MIN,MOD,PI,POW,POWER,RADIANS,RAND,ROUND,SIN,SQRT,TAN,TRUNCATE String functions: ASCII,BIN,BIT_LENGTH,CHAR,CHARACTER_LENGTH,CHAR_LENGTH,CONCAT,CONCAT_WS,CONV,ELT,E XPORT_SET,FIELD,FIND_IN_SET,HEX,INSERT,INSTR,LCASE,LEFT,LENGTH,LOAD_FILE,LOCATE,LO CATE,LOWER,LPAD,LTRIM,MAKE_SET,MATCH,MID,OCT,OCTET_LENGTH,ORD,POSITION,QUOTE,REPEA T,REPLACE,REVERSE,RIGHT,RPAD,RTRIM,SOUNDEX,SPACE,STRCMP,SUBSTRING,SUBSTRING,SUBSTR ING,SUBSTRING,SUBSTRING_INDEX,TRIM,UCASE,UPPER System functions: DATABASE,USER,SYSTEM_USER,SESSION_USER,PASSWORD,ENCRYPT,LAST_INSERT_ID,VERSION Time and Date funtions: DAYOFWEEK,WEEKDAY,DAYOFMONTH,DAYOFYEAR,MONTH,DAYNAME,MONTHNAME,QUARTER,WEEK,YEAR,H OUR,MINUTE,SECOND,PERIOD_ADD,PERIOD_DIFF,TO_DAYS,FROM_DAYS,DATE_FORMAT,TIME_FORMAT ,CURDATE,CURRENT_DATE,CURTIME,CURRENT_TIME,NOW,SYSDATE,CURRENT_TIMESTAMP,UNIX_TIME STAMP,FROM_UNIXTIME,SEC_TO_TIME,TIME_TO_SEC
The above is the detailed content of What is DatabaseMetaData in JDBC? What's the point?. For more information, please follow other related articles on the PHP Chinese website!