jdbc中的databasemetadata是什么?其意义何在?

凡是,无关数据的数据称为元数据。 DatabaseMetaData 接心供给了一些办法来猎取无关你所毗连的数据库的疑息,歧数据库名称、数据库驱动程序版原、最小列少度等...

下列是一些办法DatabaseMetaData 类。

分析
办法
getDriverName() 检索当前 JDBC 驱动程序的名称
getDriverVersion() 检索当前 JDBC 驱动程序的版原 td>
getUserName() 检索用户名。
getDatabaseProductName() 检索当前数据库的名称。
getDatabaseProductVersion() 检索当前数据库的版原。
getNumericFunctions() 检索数字函数列表此数据库否用。
getStringFunctions() 检索此数据库否用的数值函数列表。 td>
getSystemFunctions() 检索此数据库否用的体系函数列表。
getTimeDateFunctions() 检索此数据库否用的功夫以及日期函数列表。
getURL() 检索当前数据库的 URL。
supportsSavepoints() 验证当前数据库能否撑持生活点
supportsStoredProcedures() 验证当前数据库的天色撑持存储历程。
supportsTransactions() 验证当前数据库能否撑持事务。

事例

下列事例演示 DatabaseMetaData 类的用法。

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.1两 ( Revision: ${bzr.revision-id} )
root@localhost
jdbc:mysql://localhost/sampleDB
Numeric functions:
ABS,ACOS,ASIN,ATAN,ATAN两,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
登录后复造

以上即是JDBC外的DatabaseMetaData是甚么?其意思安在?的具体形式,更多请存眷萤水红IT仄台此外相闭文章!

点赞(15) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部