Follow me Stepbystep Flex tutorial

Source: Internet
Author: User

Demo13 accesses the database through spring JdbcTemplate, and the database chooses to use HSQLDB (the reader can also choose MySQL, Oracle, SQL Server, and so on).

It is necessary to copy hsqldb and spring-related jar packages to LIB (hint, if the reader does not see DEMO11 and DEMO12, it must be looked at, because these demo one is a foundation).

Configuration file does not repeat the previous demo configuration, hehe:

This demo you can visit the Http://coenraets.org/downloads/flex-spring.zip URL, the next code, this demo code are used here side of the (more classic, the author also save to write again, haha, just The next demo uses hibernate on this basis to integrate on the line.

1, configure the data source (obviously, this is also the use of spring method, Spring is not everywhere ah, hehe). Add the DataSource configuration to the Applicationcontext.xml, as follows:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSourc e">
        <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
        <property name="url" value="jdbc:hsqldb:file:FilePath(读者的数据库文件路径) "/>
        <property name="username" value="sa"/>
        <property name="password" value=""/>
</bean>

2, add business layer code, as follows:

Product.java (persistent Layer object)

Package Com.samples.spring.store;

public class Product {

Private long productId;

private String name;

Private String description;

Private String image;

Private String category;

private double price;

private int qtyinstock;

Public String getcategory () {
return category;
}

public void Setcategory (String category) {
this.category = category;
}

Public String getdescription () {
return description;
}

public void SetDescription (String description) {
this.description = description;
}

Public String GetImage () {
return image;
}

public void SetImage (String image) {
This.image = image;
}

Public String GetName () {
return name;
}

public void SetName (String name) {
THIS.name = name;
}

Public double GetPrice () {
return price;
}

public void Setprice (double) {
This.price = Price;
}

Public long GetProductID () {
return productId;
}

public void Setproductid (long productId) {
This.productid = productId;
}

public int Getqtyinstock () {
return qtyinstock;
}

public void Setqtyinstock (int qtyinstock) {
This.qtyinstock = Qtyinstock;
}


}

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.