hibernate插入图片

    技术2022-05-11  55

     /**  * 只是向数据库中插入一张图片  */ public static void insertPhoto() {  User1 u = new User1();  try {   session = HibernateSessionFactory.getSession();   Transaction tran = session.beginTransaction();   FileInputStream in = new FileInputStream("a.jpg");   byte[] p = new byte[in.available()];   in.read(p);   in.close();   u.setPhoto1(p);   u.setName("babe");   u.setPwd("babe");   session.save(u);   tran.commit();  } catch (Exception e) {   e.printStackTrace();

      } finally {   HibernateSessionFactory.closeSession();  }

     } 


    最新回复(0)