Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
- <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/itaprojekat?zeroDateTimeBehavior=convertToNull</property>
- <property name="hibernate.connection.username">root</property>
- <property name="hibernate.connection.password">2007991710126</property>
- <property name="hibernate.connection.autocommit">true</property>
- <property name="hibernate.show_sql">true</property>
- <property name="hibernate.hbm2ddl.auto">update</property>
- <mapping class="itaprojekat.Kategorija"></mapping>
- </session-factory>
- </hibernate-configuration>
- public class HibernateUtil {
- private static Session sesija = null;
- public static Session getSession(){
- if(sesija==null){
- Configuration cfg = new Configuration();
- cfg.configure("/config/hibernate.cfg.xml");
- ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
- SessionFactory sessionFactory = cfg.buildSessionFactory(serviceRegistry);
- sesija = sessionFactory.openSession();
- }
- return sesija;
- }
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- Session sesija = HibernateUtil.getSession();
- sesija.beginTransaction();
- InputContext ic = tfNaziv.getInputContext(); //tfNaziv is my textfield
- Kategorija k = new Kategorija();
- k.setNaziv(ic);
- sesija.save(k);
- sesija.getTransaction().commit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement