KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > SampleResultSetScenario


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /** SampleResultSetScenario.java
25 **/

26
27 package sample;
28
29 import javax.naming.*;
30 import javax.resource.cci.*;
31 import java.util.Iterator JavaDoc;
32 import java.sql.SQLException JavaDoc;
33 import javax.resource.ResourceException JavaDoc;
34
35 public class SampleResultSetScenario {
36
37   public void method() {
38     
39     try {
40       Context nc = new InitialContext();
41
42       // JNDI lookup for ConnectionFactory
43
ConnectionFactory cf = (ConnectionFactory)nc.lookup(
44                  "java:comp/env/eis/ConnectionFactory");
45       Connection cx = cf.getConnection();
46
47       // Create an Interaction.
48
Interaction ix = cx.createInteraction();
49
50       // Create an InteractionSpec and set properties.
51
InteractionSpecImpl ixSpec = new InteractionSpecImpl();
52       ixSpec.setFunctionName("<NAME OF FUNCTION>");
53       ixSpec.setInteractionVerb(InteractionSpec.SYNC_SEND_RECEIVE);
54
55       RecordFactory rf = cf.getRecordFactory();
56       
57       // Create an input MappedRecord. The component code adds values
58
// based on the meta information it has accessed from the metadata
59
// repository. The name of the Record acts as a pointer to the
60
// meta information (stored in the metadata repository) for a
61
// specific record type.
62
MappedRecord input = rf.createMappedRecord("Name of Record");
63       input.put("<key: element1>", new String JavaDoc("<VALUE1>"));
64       input.put("<key: element2>", new String JavaDoc("<VALUE2>"));
65
66       // Execute the Interaction
67
ResultSet rs = (javax.resource.cci.ResultSet JavaDoc)ix.execute(ixSpec, input);
68
69       // Iterate over the ResultSet. The example here positions the
70
// cursor on the first row and then iterates forward through
71
// the contents of the ResultSet. The getXXX methods are used
72
// to retrieve column values:
73
rs.beforeFirst();
74       while (rs.next()) {
75     // Look at the current row of the resultSet
76
}
77     }
78     catch (NamingException ne) {
79       return;
80     }
81     catch (ResourceException JavaDoc e) {
82       return;
83     }
84     catch (SQLException JavaDoc e) {
85       return;
86     }
87   }
88
89
90
91   public static void main(String JavaDoc[] args) {
92   }
93
94 }
95
Popular Tags