Simple implementation of database access --- edainfo-model (iii) -- simple example

Source: Internet
Author: User

The following describes the development steps:
First, create a jdbc/edainfo data source under Tomcat5.X. The databases can be oracle, SQL server, and mysql. The table structure is as follows:
Create table example (
Id varchar (13) not null,
Name varchar (50) NULL,
Address varchar (50) NULL
) ON [PRIMARY]
The id is the primary key.
The content of datasource. xml is as follows:
<? Xml version = "1.0" encoding = "gb2312"?>
<Database>
<Model name = "exampleModel">
<Tablename> example </tablename>
<Columns>
<Column type = "0" name = "id" tabColumn = "id"/>
<Column type = "0" name = "name" tabColumn = "name"/>
<Column type = "0" name = "address" tabColumn = "address"/>
<Column type = "2" name = "pageNum" tabColumn = "pageNum"/>
<Column type = "2" name = "operation" tabColumn = "operation"/>
</Columns>
<Relations>
</Relations>
<Pk tabColumn = "id"/>
<Pages>
<Page name = "fore" size = "20" viewPage = "5"/>
</Pages>
</Model>
</Database>
Init-config.xml has been introduced before, here is not detailed introduction.
Place both of the above files under the WEB-INF directory.
Create a net. edainfo. filter. SetCharacterEncodingFilter filter in web. xml.
Create ExampleModel. java as follows:
Package net. edainfo. example;
Import java. util. Map;
Import net. edainfo. db. DBModel;
Import net. edainfo. db. ModelException;
Import net. edainfo. util. format. Encode;
Import net. edainfo. util. format. StringProcessor;
Public class ExampleModel extends DBModel {
Public ExampleModel (Map dataBase) throws ModelException {
Super ("exampleModel", dataBase );
}
Public void setId (String id) throws ModelException {
Set ("id", id );
}

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.