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 ("");