Advertisement
sergAccount

Untitled

Apr 4th, 2021
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 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 com.spec;
  7.  
  8. import com.spec.util.DataBaseUtil;
  9. import java.sql.Connection;
  10. import java.sql.DatabaseMetaData;
  11. import java.sql.SQLException;
  12.  
  13. public class Test {
  14.     // получим инофрмацию о версии СУБД и версии драйвера
  15.     public static void printMeta(){
  16.         // после работы с объектом типа Connection необходимо его закрыть - вызвать метод close        
  17.         // try-with-resources        
  18.         try(Connection c = DataBaseUtil.getConnection()){
  19.             DatabaseMetaData m = c.getMetaData();
  20.             //
  21.             System.out.println("m.getDatabaseProductName()=" + m.getDatabaseProductName());
  22.             System.out.println("m.getDatabaseProductVersion()=" + m.getDatabaseProductVersion());
  23.             System.out.println("m.getJDBCMajorVersion()=" + m.getJDBCMajorVersion());
  24.             System.out.println("m.getDriverName()="       + m.getDriverName());
  25.         } catch (SQLException ex) {
  26.             ex.printStackTrace();
  27.         }
  28.         /*finally{
  29.           c.close()  
  30.         }*/
  31.     }    
  32.     //
  33.     public static void main(String[] args) {        
  34. //        try {
  35. //            Connection c = DataBaseUtil.getConnection();
  36. //            System.out.println("c=" + c);
  37. //        } catch (SQLException ex) {
  38. //            ex.printStackTrace();
  39. //        }      
  40.           printMeta();
  41.     }    
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement