Tomcat + MySQL + ultraedit: A 10-minute initial experience of Hibernate

Source: Internet
Author: User
Tags connection pooling ultraedit

The first time I came into contact with hibernate today, I found that the previous entry excellent posts did not involve the most pop combinations such as Tomcat + MySQL, and all of them were developed with IDE, either JBuilder or eclipse, simply put, I will use the simplest method, Tomcat (5.0.19) + MySQL (4) + ultraedit, to implement a basic Hibernate query, so as to facilitate later learning.

1. Ensure that your MySQL instance works properly.
[Code: 1]
Create Table CAT (
Cat_id varchar (20) not null,
Name varchar (20) not null,
Sex char (1 ),
Weight float,
Primary Key (cat_id)
);

Insert cat values ('1', 'ada ', 'F', 5 );
Insert cat values ('2', 'belinda ', 'F', 10 );
Commit;
[/Code: 1]

2. Ensure that your Tomcat works properly. Then stop tomcat.
Add the following content to {tomcat_home}/CONF/server. xml:
[Code: 1]
<Context Path = "/hellohibernate" docbase = "hellohibernate" reloadable = "true">
<Resource Name = "JDBC/hellohibernate" Scope = "retriable" type = "javax. SQL. datasource"/>
<Resourceparams name = "JDBC/hellohibernate">
<Parameter>
<Name> factory </Name>
<Value> org. Apache. commons. DBCP. basicperformancefactory </value>
</Parameter>

<! -- DBCP database connection settings -->
<Parameter>
<Name> URL </Name>
<Value> JDBC: mysql: // localhost: 3306/test </value>
</Parameter>
<Parameter>
<Name> driverclassname </Name> <value> com. MySQL. JDBC. Driver </value>
</Parameter>
<Parameter>
<Name> username </Name>
<Value> yourusername </value>
</Parameter>
<Parameter>
<Name> password </Name>
<Value> yourpassword </value>
</Parameter>

<! -- DBCP Connection Pooling options -->
<Parameter>
<Name> maxwait </Name>
<Value> 3000 </value>
</Parameter>
<Parameter>
<Name> maxidle </Name>
<Value> 100 </value>
</Parameter>
<Parameter>
<Name> maxactive </Name>
<Value> 10 </value>
</Parameter>
</Resourceparams>
</Context>
[/Code: 1]

3. Rename the attachment hellohibernate.zip to hellohibernate. War, and throw it to {tomcat_home}/webapps to restart tomcat.

4. You will find hellohibernate has been automatically deployed, copy the following files to {tomcat_home}/webapps/hellohibernate/WEB-INF/lib:
Hibernate2.jar
Log4j-1.2.8.jar
Commons-collections-2.1.jar
Commons-logging-1.0.3.jar
Dom4j-1.4.jar
Cglib-2.0-rc2.jar
Odmg-3.0.jar
Ehcache-0.6.jar
JTA. Jar
(In fact, I could have packed them into war files, but now the war file reaches 2 MB, and it is only 8 KB)

5. http: // localhost: 9090/hellohibernate/servlet/hellohibernateservlet
If everything is correct, you can see the cat information.

Hope it's helpful, thanks

 

Hellohibernate.zip (7.1 KB)

From: http://www.javaeye.com/topic/4077

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.