通常,有关数据的数据称为元数据。 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 updatesmysql-ab jdbc drivermysql-connector-java-5.1.12 ( revision: ${bzr.revision-id} )root@localhostjdbc:mysql://localhost/sampledbnumeric 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,truncatestring functions:ascii,bin,bit_length,char,character_length,char_length,concat,concat_ws,conv,elt,export_set,field,find_in_set,hex,insert,instr,lcase,left,length,load_file,locate,locate,lower,lpad,ltrim,make_set,match,mid,oct,octet_length,ord,position,quote,repeat,replace,reverse,right,rpad,rtrim,soundex,space,strcmp,substring,substring,substring,substring,substring_index,trim,ucase,uppersystem functions:database,user,system_user,session_user,password,encrypt,last_insert_id,versiontime and date funtions:dayofweek,weekday,dayofmonth,dayofyear,month,dayname,monthname,quarter,week,year,hour,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_timestamp,from_unixtime,sec_to_time,time_to_sec
以上就是jdbc中的databasemetadata是什么?其意义何在?的详细内容。
