Use DatabaseMetaDate to obtain database information

Source: Internet
Author: User


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

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.