일반적으로 데이터에 대한 데이터를 메타데이터라고 합니다. 데이터베이스메타데이터 인터페이스는 데이터베이스 이름, 데이터베이스 드라이버 버전, 최대 열 길이 등과 같이 연결된 데이터베이스에 대한 정보를 얻는 방법을 제공합니다...
다음은 DatabaseMetaData의 몇 가지 방법입니다. 수업.
| 메소드 | 설명 |
|---|---|
| getDriverName() | 현재 JDBC 드라이버의 이름을 검색합니다. |
| getDriverVersion() | 현재 JDBC 드라이버의 버전을 검색합니다. |
| getUserName() | 사용자 이름을 검색합니다. |
| getDatabaseProductName() | 현재 데이터베이스의 이름을 검색합니다. |
| getDatabaseProductVersion() | 현재 데이터베이스의 버전을 검색합니다. |
| getNumericFunctions() | 이 데이터베이스에서 사용할 수 있는 숫자 함수 목록을 검색합니다. |
| getStringFunctions() | 이 데이터베이스에서 사용할 수 있는 숫자 함수 목록을 검색합니다. |
| getSystemFunctions() | 이 데이터베이스에서 사용할 수 있는 시스템 기능 목록을 검색합니다. |
| getTimeDateFunctions() | 이 데이터베이스에서 사용할 수 있는 시간 및 날짜 함수 목록을 검색합니다. |
| getURL() | 현재 데이터베이스의 URL을 검색합니다. |
| Savepoints() 지원 | 현재 데이터베이스가 저장 지점을 지원하는지 확인합니다. |
| StoredProcedures() 지원 | 현재 데이터베이스가 저장 프로시저를 지원하는지 확인합니다. |
| 트랜잭션() 지원 | 현재 데이터베이스가 트랜잭션을 지원하는지 확인합니다. |
예시
다음 예제는 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.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