Use databasemetadate to obtain database information

Source: Internet
Author: User
Tags mathematical functions

Import java. SQL .*;
Public class getdbinfo
{
Public getdbinfo ()
{
}

Public static void main (string [] ARGs)
{
Try {
Class. forname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver"). newinstance ();
String url = "JDBC: Microsoft: sqlserver: // gaoxiang: 1433; databasename = Master ";
String user = "daryl715 ";
String pass = "1234 ";
String S;
Connection con = drivermanager. getconnection (URL, user, pass );
Databasemetadata dbmd = con. getmetadata ();
S = dbmd. getdrivername ();
System. Out. println ("The driver name is:" + S );
System. Out. println ("");

S = dbmd. getdatabaseproductname ();
System. Out. println ("Database Name:" + S );
System. Out. println ("");

Resultset rs = dbmd. getschemas ();
System. Out. println ("mode names :");
While (Rs. Next ())
System. Out. Print ("" + Rs. getstring (1 ));
System. Out. println ();

S = dbmd. getsqlkeywords ();
System. Out. println ("keyword in SQL:" + S );
System. Out. println ("");

Int max = dbmd. getmaxcolumnnamelength ();
System. Out. println ("the maximum length of the column name can be:" + max );
System. Out. println ("");

Max = dbmd. getmaxtablenamelength ();
System. Out. println ("the maximum table name length can be:" + max );
System. Out. println ("");

Max = dbmd. getmaxcolumnsinselect ();
System. Out. println ("the maximum length of the column name that can be returned by a select clause is:" + max );
System. Out. println ("");

Max = dbmd. getmaxtablesinselect ();
System. Out. println ("the maximum number of tables a SELECT statement can access:" + max );
System. Out. println ("");

Max = dbmd. getmaxcolumnsintable ();
System. Out. println ("Maximum number of columns allowed in the table:" + max );
System. Out. println ("");

Max = dbmd. getmaxconnections ();
System. Out. println ("number of concurrent users:" + max );
System. Out. println ("");

Max = dbmd. getmaxstatementlength ();
System. Out. println ("maximum allowed SQL statement length:" + max );
System. Out. println ("");

S = dbmd. getnumericfunctions ();
System. Out. println ("list of all mathematical functions in the database:" + S );
System. Out. println ("");

S = dbmd. getstringfunctions ();
System. Out. println ("list of all string functions in the database:" + S );
System. Out. println ("");

S = dbmd. getsystemfunctions ();
System. Out. println ("list of all system functions of the database:" + S );
System. Out. println ("");

S = dbmd. gettimedatefunctions ();
System. Out. println ("list of all database Date and Time Functions:" + S );
System. Out. println ("");

Rs = dbmd. gettypeinfo ();
While (Rs. Next ())
{
System. Out. Print ("data type name:" + Rs. getstring (1 ));
System. Out. Print ("Data Type:" + Rs. getstring (2 ));
System. Out. Print ("precision:" + Rs. getstring (3 ));
System. Out. println ("base:" + Rs. getstring (18 ));
}
System. Out. println ("");

S = dbmd. geturl ();
System. Out. println ("URL of this database:" + S );
System. Out. println ("");

S = dbmd. GetUserName ();
System. Out. println ("user of this database:" + S );
System. Out. println ("");

String [] T = {"table", "View "};
Rs = dbmd. gettables (null, "HR", "%", t );
While (Rs. Next ()){
System. Out. Print ("directory name:" + Rs. getstring (1 ));
System. Out. Print ("Mode name:" + Rs. getstring (2 ));
System. Out. Print ("table name:" + Rs. getstring (3 ));
System. Out. Print ("Table type:" + Rs. getstring (4 ));
System. Out. println ("comment:" + Rs. getstring (5 ));
}
System. Out. println ("");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.