Advertisement
sergAccount

Untitled

Apr 4th, 2021
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 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.model.Person;
  9. import com.spec.service.ProductService;
  10. import com.spec.util.DataBaseUtil;
  11. import java.sql.Connection;
  12. import java.sql.DatabaseMetaData;
  13. import java.sql.SQLException;
  14. import java.util.List;
  15.  
  16. public class Test {
  17.  
  18.     // получим инофрмацию о версии СУБД и версии драйвера
  19.     public static void printMeta() {
  20.         // после работы с объектом типа Connection необходимо его закрыть - вызвать метод close        
  21.         // try-with-resources        
  22.         try (Connection c = DataBaseUtil.getConnection()) {
  23.             DatabaseMetaData m = c.getMetaData();
  24.             //
  25.             System.out.println("m.getDatabaseProductName()=" + m.getDatabaseProductName());
  26.             System.out.println("m.getDatabaseProductVersion()=" + m.getDatabaseProductVersion());
  27.             System.out.println("m.getJDBCMajorVersion()=" + m.getJDBCMajorVersion());
  28.             System.out.println("m.getDriverName()=" + m.getDriverName());
  29.         } catch (SQLException ex) {
  30.             ex.printStackTrace();
  31.         }
  32.         /*finally{
  33.           c.close()  
  34.         }*/
  35.     }
  36.  
  37.     //
  38.     public static void main(String[] args) {
  39. //        try {
  40. //            Connection c = DataBaseUtil.getConnection();
  41. //            System.out.println("c=" + c);
  42. //        } catch (SQLException ex) {
  43. //            ex.printStackTrace();
  44. //        }      
  45.         printMeta();
  46.  
  47.         ProductService service = new ProductService();
  48.         try {
  49.             List<Person> list = service.getAll();
  50.             System.out.println("list.size=" + list.size());
  51.            
  52.             Person p = service.getPerson(3);
  53.             if(p!=null){
  54.                 System.out.println("p.name=" + p.getName());
  55.             }
  56.             //
  57.             service.createPerson(new Person(0, "ZZZZsadfasfasf"));
  58.         } catch (Exception e) {
  59.             e.printStackTrace();
  60.         }
  61.     }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement