| | |
Create hibernate.cfg.xml while program is running
![]() |
•
•
Join Date: Apr 2007
Posts: 34
Reputation:
Solved Threads: 1
how to connet to database using hibernate, because i create hibernate.cfg.xml while is running
i have build simple application for test connection to database using hibernate.
when write application i'm not write hibernate.cfg.xml, but i want create while running.
so when i click button show error like this
[code]
"
"Jun 9, 2008 8:59:19 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.1
Jun 9, 2008 8:59:19 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Jun 9, 2008 8:59:19 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Jun 9, 2008 8:59:19 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Jun 9, 2008 8:59:19 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Jun 9, 2008 8:59:19 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
error connected /hibernate.cfg.xml not found
"
[\code]
this my code
this file hibernate.cfg.xml i create while running
because i want make connection more flexible using hibernate, who user can connect to other database or server.
thx
i have build simple application for test connection to database using hibernate.
when write application i'm not write hibernate.cfg.xml, but i want create while running.
so when i click button show error like this
[code]
"
"Jun 9, 2008 8:59:19 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.1
Jun 9, 2008 8:59:19 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Jun 9, 2008 8:59:19 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Jun 9, 2008 8:59:19 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Jun 9, 2008 8:59:19 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Jun 9, 2008 8:59:19 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
error connected /hibernate.cfg.xml not found
"
[\code]
this my code
Java Syntax (Toggle Plain Text)
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { Session session = null; try{ SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session =sessionFactory.openSession(); Object[] options = {"Yes"}; int n = JOptionPane.showOptionDialog(null, "connect success","test",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null, options,options[0]); }catch(Exception e){ System.out.println("error connected "+ e.getMessage()); Object[] options = {"Yes"}; int n = JOptionPane.showOptionDialog(null, "error connected\n"+ e,"test",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null, options,options[0]); } }
this file hibernate.cfg.xml i create while running
Java Syntax (Toggle Plain Text)
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/hibernatetutorial</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password"></property> <property name="hibernate.connection.pool_size">10</property> <property name="show_sql">true</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.hbm2ddl.auto">update</property> </session-factory> </hibernate-configuration>
because i want make connection more flexible using hibernate, who user can connect to other database or server.
thx
Last edited by onsir; Jun 9th, 2008 at 6:29 am.
![]() |
Other Threads in the Java Forum
- Previous Thread: EJB based application to Stand Alone application
- Next Thread: Path setting problem in jdk1.5
| Thread Tools | Search this Thread |
2dgraphics @param account affinetransform android api apple applet application arc arguments array automation banking binary binarytree bluetooth chatprogramusingobjects class client code color compare component count database derby design detection eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide if_statement image inheritance integer j2me java java.xls javadesktopapplications javaprojects jlabel jni jpanel julia keytool keyword linux list macintosh map method methods midlethttpconnection mobile monitoring netbeans nullpointerexception object open-source pong problem producer program project projectideas property reference replaysolutions ria rim scanner server set size sms sourcelabs splash sql swing terminal threads transforms tree ui unicode validation web windows





