IDRS Data Input
A new feature of the IDRS in version 1.5
is the ability to input data into a database. Inputting data is just as
easy as extracting data from a database. To explore this we will work off
of the Data Paging Example presented after the release of IDRS 1.4 by adding
a page that will allow new names to be entered into the database. This
example assumes that you have read and all of the previous tutorials, especially
the Data Paging Sample.
This sample will simply present the user with a form to enter a first
name, last name, phone number, id and email address. The data will be entered
via a simple insert statement. This is a very simple page,
input.rml,
which simply asks for all of the given variables. Here is the RML page
that will be used:
<rml>
<ishtml>true</ishtml>
<head>
<db id="input">
<direction>input</direction>
<dbname>jdbc:postgresql:samples</dbname>
<sql>
<src>
INSERT INTO
contacts VALUES(?,?,?,?,?);
</src>
<vartype>int</vartype>
<vartype>string</vartype>
<vartype>string</vartype>
<vartype>string</vartype>
<vartype>string</vartype>
</sql>
</db>
</head>
<body>
<center>
<h1>Added Record To Phone Dirrectory</h1><p>
<inputresults>input</inputresults>
rows effected
</center>
</body>
</rml>
As you can see, this page is fairly simple.
You'll notice a new tag in the <db> tag, <direction>. This tells
the IDRS whether or not the <db> will retrieve records or deliver input
to the database. If the <direction> tag is omitted, the IDRS assumes
that the <db> will retrieve data from the database.
The <body>also has a new tag, <results>.
This tag allows you to find out how many records were affected by the INSERT
or UPDATE statement.
Now
that the RML document is built, lets build the HTML for IDRSParams,
inputvar.html:
ID : <input type="text" name="input_id"><br>
First Name : <input type="text" name="input_first"><br>
Last Name : <input type="text" name="input_last"><br>
Phone : <input type="text" name="input_phone"><br>
Email : <input type="text" name="input_email"><br>
<input
type="submit"><input type="reset">
This is a simple set of HTML tags. Now that we have those two pieces,
lets deploy the report using the InsertToIDRS class :
ID |
4 |
Name |
test_Input |
Source File |
input.rml |
Groups |
1,2, |
Var Source |
inputvar.html |
Is File |
false |
Parameters |
input_id:input_first:input_last:input_phone:input_email: |
Connections |
jdbc:postgresql:samples, |
java
InsertToIDRS -isgvfpc org.postgresql.Driver jdbc:postgresql:idrs webadmin
123asd 1 test_Input input.rml 1,2, inputvar.html false input_id:input_first:input_last:input_phone:input_email:
jdbc:postgresql:samples,
That's all that's needed to create an RML
page that can handle data input. For any production work business logic
will have to be applied to all data before it is put into the database.