Abdullah047

SchemaInfo

Sep 2nd, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package sqltest;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DatabaseMetaData;
  10. import java.sql.DriverManager;
  11. import java.sql.ResultSet;
  12. import java.sql.SQLException;
  13.  
  14. /**
  15.  *
  16.  * @author Abdullah
  17.  */
  18. public class ScheemaInfo {
  19.         public static void main(String[] args) throws SQLException{
  20.         String catalog=null;
  21.         String SchemaPattern=null;
  22.         String tableNamePattern=null;
  23.         String coulmnNamePattern=null;
  24.         String Types[]=null;
  25.             String url="jdbc:mysql://localhost:3306/demo?autoReconnect&useSSL=false";
  26.         String user="root"  ;
  27.         String password="abdullah";
  28.        
  29.         Connection connect=DriverManager.getConnection(url,user, password);
  30.         DatabaseMetaData MD=connect.getMetaData();
  31.    ResultSet  result=     MD.getTables(catalog, SchemaPattern, tableNamePattern, Types);
  32.              System.out.println("List of Tables");
  33.              System.out.println("--------------------------------------");
  34.    
  35.         while(result.next()){
  36.         System.out.println(result.getString("TABLE_NAME"));
  37.        
  38.                 }
  39.              System.out.println("List of Columns");
  40.              System.out.println("------------------------------------------");
  41.  ResultSet  result1=MD.getColumns(catalog, SchemaPattern, tableNamePattern, coulmnNamePattern);
  42.   while(result1.next()){
  43.         System.out.println(result1.getString("COLUMN_NAME"));
  44.        
  45.                 }
  46.        
  47.         }
  48. }
Add Comment
Please, Sign In to add comment