Database Meta Data Analysis Demo

Source: Internet
Author: User

Core class: DatabaseMetaData, ResultSetMetaData


1System.err.println ("**********************************");2Connection conn=Datasourceutils.getdatasource (). getconnection ();3DatabaseMetaData Dbmd=conn.getmetadata ();//get information about the result set conn, such as field name, number of fields, etc.4ResultSet set= dbmd.getcatalogs ();//get all database names5 while(Set.next ())6 {7String name=set.getstring ("Table_cat");8System.err.println ("= =" +name);9 }TenSystem.err.println ("================================="); OneString dbname=dbmd.getdatabaseproductname (); A System.err.println (dbname); -System.err.println ("================================="); - //The first two parameters, if NULL, are the default connected database, or the table for the specified database if the database is specified; the //The fourth parameter will be queried if it is null,tables,views; you can specify to find tables or views or all -ResultSet set2= dbmd.gettables ("jdbcdb", "jdbcdb",NULL,Newstring[]{"VIEW"}); - while(Set2.next ()) { -String name= set2.getstring ("table_name"); +SYSTEM.ERR.PRINTLN ("* * * *" +name); - } +System.err.println ("================================="); AStatement stmt =conn.createstatement (); atStmt.execute ("Use jdbcdb");//go to the JDBC database -String sql= "SELECT * from Users"; -ResultSet rs=stmt.executequery (SQL); -ResultSetMetaData rsdadata= rs.getmetadata ();//get information about the result set RS - intCount= Rsdadata.getcolumncount ();//get total number of rows - System.err.println (count); inList<string> list=NewArraylist<string>(); - for(inti=0;i<count;i++) to { +String Name=rsdadata.getcolumnname (i+1);//Gets the row name (the index in the database starts from 1) -System.err.print (name+ "\t\t"); the List.add (name); * } $System.err.println ("");Panax Notoginseng while(Rs.next ()) - { the for(String s:list) + { AString value=rs.getstring (s); theSystem.err.print (value+ "\t\t"); + } -System.err.println (""); $}

Database Meta Data Analysis Demo

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.