There is a friend asked. If you have a connection, you know the situation of the currently linked library? In fact, you have already connected, you can know the situation in this library, but not only the situation,
Sometimes (I only saw it once), we don't know the structure of its structure or in a new database. How do we get the database?
The real example is the case. My friend's company received a single child. The database used by the other party is what / "titanium /", saying that the truth is because I have never known that there is still this database. Not don't say how to visit, now friends want to see what is there / "things /", of course, is an armless exhibition. So I have to find me.
After receiving the call, I first asked him to run on the platform. If it is connected, he said that it can establish an ODBC data source under Windows. Haha, it is said that you can build Connection with Java. OK
Can only create Connection, then you can get all the meta information of this database:
DatabaseMetadata dbmd = conn.getMetadata (); then you can get the following letter from this object
interest:
getURL (); // Returns the URL of the link with this database, of course, is known, do you want you?
GetUserName (); // Return to the user of this database, the same
IsreadOnly (); if the database is read-only
getDatabaseProduceName (); // Database Product Name
GetDatabaseProduceVersion (); // version number
GetDrivername (); // driver
GetDriverVersion (); // Driver version
There is no significance of the above content.
ResultSet GetTables (String Catalog,
String Schemapattern,
String TablenamePattern,
String [] Types)
You can get all the cases of / "table /" in the library, where the tables include tables, views, system tables, temporary space, alias, synonyms
For each parameter:
String Catalog, table catalog, possible for null, / "null /" matches all
String Schemapattern, outline of the table, the same
String TablenamePattern, table name, same
String [] Types, Table, / "NULL /" matches all, available types:
Table, View, Sysem Table, Global Temporary, Local Temporary, Alias, Synonym
E.g:
DatabaseMetadata dbmd = conn.getMetadata ();
ResultSet RS = DBMD.GETTABLES (NULL, NULL, NULL, NULL);
ResultSetmetaData RSMD = rs.getMetadata ();
INT j = rsmd.getColumnCount ();
For (INT i = 1; i <= j; i ) {
Out.print (RSMD.GetColumnLabel (i) / "// t /");
}
Out.println ();
While (rs.next ()) {
For (INT i = 1; i <= j; i ) {
Out.print (rs.getstring (i) / "// t /");
}
Out.println ();
}
For information on the columns in a more detailed table, you can use dBMD (not RSMD) .getColumns (
String Catalog,
String Schemapattern,
String TablenamePattern,
String columnnamepattern
)
Not only can I get information in RSMD, but also obtain the size, decimal number, accuracy, default, and listing in the table.
There are also two ways, call, and get the table information, you can get information of stored procedures and indexes: ResultSet getProcedures
String Catalog,
String Schemapattern,
String ProcedurePattern
);
ResultSet getIndexinfo
String Catalog,
String Schemapattern,
String Table,
Boolean Unique, Boolean Approximate
);