In the inputText_action method obtain
a connection with the Oracle database using the Oracle datasource
configured in JDeveloper.
InitialContext initialContext = new InitialContext();
javax.sql.DataSource ds =
(javax.sql.DataSource)initialContext.lookup(???java:com
p/env/jdbc/OracleDBConnectionDS???);
java.sql.Connection connection = ds.getConnection();
Create a Statement object with a scrollable result set type to run an
SQL statement.
Statement stmt =
connection.createStatement(ResultSet.TYPE_SCROLL_INSE
NSITIVE,
ResultSet.CONCUR_READ_ONLY);
Obtain the Catalog ID value specified in the input form and create a
SQL query to run in the Oracle database.
String catalogID = (String)inputText1.getValue();
String query =
???SELECT * from Catalog WHERE CATALOGID=??? +
?????™??? + catalogID + ?????™???;
Run the SQL query and obtain a result set.
rs = stmt.executeQuery(query);
If the result set is not empty, set the validation message to ???Catalog Id
is not valid.???, set the field values, and disable the command button.
7.6 Processing an Ajax Request 149
if (rs.next()) {
inputText2.setValue(rs.getString(2));
inputText3.setValue(rs.getString(3));
inputText4.setValue(rs.getString(4));
inputText5.setValue(rs.getString(5));
inputText6.setValue(rs.getString(6));
outputText1.setValue(new String(???Catalog Id is
not Valid???));
commandButton1.setDisabled(true);
}
If the result set is empty, implying that the Catalog ID specified in the
input form is not already in the database, set the validation message to,
???Catalog Id is valid.
Pages:
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140