Tutorials to .com

Tutorials to .com » Jsp » Database » Access to database information using DatabaseMetaDate

Access to database information using DatabaseMetaDate

Print View , by: iSee ,Total views: 10 ,Word Count: 1116 ,Date: Sat, 18 Apr 2009 Time: 8:37 PM

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 ( "Driver name is:" + s);
System.out.println ( "");

s = dbmd.getDatabaseProductName ();
System.out.println ( "Database name is:" + s);
System.out.println ( "");

ResultSet rs = dbmd.getSchemas ();
System.out.println ( "model name are:");
while (rs.next ())
System.out.print ( "" + rs.getString (1));
System.out.println ();

s = dbmd.getSQLKeywords ();
System.out.println ( "SQL in the key word for:" + s);
System.out.println ( "");

int max = dbmd.getMaxColumnNameLength ();
System.out.println ( "list can be a maximum length:" + max);
System.out.println ( "");

max = dbmd.getMaxTableNameLength ();
System.out.println ( "Table name maximum length can be:" + max);
System.out.println ( "");

max = dbmd.getMaxColumnsInSelect ();
System.out.println ( "clause can return a select list of the largest series of the maximum length, however is:" + max);
System.out.println ( "");

max = dbmd.getMaxTablesInSelect ();
System.out.println ( "a SELECT statement can access up to the number of tables:" + max);
System.out.println ( "");


max = dbmd.getMaxColumnsInTable ();
System.out.println ( "table to allow the maximum number of rows:" + max);
System.out.println ( "");

max = dbmd.getMaxConnections ();
System.out.println ( "Number of concurrent users access:" + max);
System.out.println ( "");

max = dbmd.getMaxStatementLength ();
System.out.println ( "SQL statement of the maximum allowable length:" + max);
System.out.println ( "");

s = dbmd.getNumericFunctions ();
System.out.println ( "database list of all the mathematical functions:" + s);
System.out.println ( "");

s = dbmd.getStringFunctions ();
System.out.println ( "database list of all string functions:" + s);
System.out.println ( "");

s = dbmd.getSystemFunctions ();
System.out.println ( "database list of all the system function:" + s);
System.out.println ( "");

s = dbmd.getTimeDateFunctions ();
System.out.println ( "date database of all the list function of time:" + 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 ( "Accuracy:" + rs.getString (3));
System.out.println ( "base:" + rs.getString (18));
)
System.out.println ( "");

s = dbmd.getURL ();
System.out.println ( "This database url:" + s);
System.out.println ( "");

s = dbmd.getUserName ();
System.out.println ( "The database user:" + 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 ( "model name:" + rs.getString (2));
System.out.print ( "Table Name:" + rs.getString (3));
System.out.print ( "Table type:" + rs.getString (4));
System.out.println ( "Notes:" + rs.getString (5));
)
System.out.println ( "");

rs = dbmd.getPrimaryKeys (null, "HR", "EMPLOYEES");
while (rs.next ()) (
System.out.print ( "directory name:" + rs.getString (1));
System.out.print ( "model name:" + rs.getString (2));
System.out.print ( "Table Name:" + rs.getString (3));
System.out.print ( "out of sequence number:" + rs.getString (4));
System.out.print ( "out of sequence number:" + rs.getString (5));
System.out.println ( "Primary Key Name:" + rs.getString (6));
)
System.out.println ( "");

rs = dbmd.getTableTypes ();
System.out.println ( "table types are:");
while (rs.next ())
System.out.print ( "" + rs.getString (1));
System.out.println ();
System.out.println ( "");

rs = dbmd.getColumns (null, "HR", "EMPLOYEES", "%");
System.out.println ( "table" + "list" + "data type" + "local type name" + "out of size" + "number of decimal places" + "data base" + "whether or not empty" + "index");
while (rs.next ()) (
System.out.print (rs.getString (3) + "");
System.out.print (rs.getString (4) + "");
System.out.print (rs.getString (5) + "");
System.out.print (rs.getString (6) + "");
System.out.print (rs.getString (7) + "");
System.out.print (rs.getString (9) + "");
System.out.print (rs.getString (10) + "");
System.out.print (rs.getString (11) + "");
System.out.println (rs.getString (17) + "");
)
System.out.println ( "");

rs = dbmd.getIndexInfo (null, "HR", "EMPLOYEES", false, false);

System.out.println ( "table" + "index of" + "index of type" + "index out of" + "index of the order of" + "number of decimal places" + "data base" + "whether or not empty" + " index ");
while (rs.next ()) (
System.out.print (rs.getString (3) + "");
System.out.print (rs.getString (6) + "");
System.out.print (rs.getString (7) + "");
System.out.print (rs.getString (9) + "");
System.out.println (rs.getString (10) + "");
)
System.out.println ( "");

rs.close ();
con.close ();
)
catch (Exception e) (System.out.println (e);)
new GetDBInfo ();
)
)



Jsp And Database Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.