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;
}
}