KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ist > coach > coachEmfServices > EmfBasicLog > AnyTypeTrans


1 package ist.coach.coachEmfServices.EmfBasicLog;
2
3 import java.sql.*;
4 import org.omg.CORBA.Any JavaDoc;
5 import org.omg.CORBA.TCKind JavaDoc;
6
7 public class AnyTypeTrans
8 {
9     /************************************************************************/
10     /* METHOD 'toDB' */
11     /************************************************************************/
12         public int toDB(PreparedStatement dbStatement, int position, Any JavaDoc anyParam)
13     {
14        TCKind JavaDoc J = null;
15
16        try
17        {
18         if ((anyParam.type()).kind() == TCKind.tk_string) {
19             dbStatement.setString(position, anyParam.extract_string());
20             J = TCKind.tk_string;
21         }
22         if ((anyParam.type()).kind() == TCKind.tk_boolean) {
23             dbStatement.setBoolean(position, anyParam.extract_boolean());
24             J = TCKind.tk_boolean;
25         }
26         if ((anyParam.type()).kind() == TCKind.tk_double) {
27             dbStatement.setDouble(position, anyParam.extract_double());
28             J = TCKind.tk_double;
29         }
30         if ((anyParam.type()).kind() == TCKind.tk_float) {
31             dbStatement.setFloat(position, anyParam.extract_float());
32             J = TCKind.tk_float;
33         }
34         if ((anyParam.type()).kind() == TCKind.tk_ulong) {
35             dbStatement.setInt(position, anyParam.extract_ulong());
36             J = TCKind.tk_ulong;
37         }
38         if ((anyParam.type()).kind() == TCKind.tk_long) {
39             dbStatement.setInt(position, anyParam.extract_long());
40             J = TCKind.tk_long;
41         }
42         if ((anyParam.type()).kind() == TCKind.tk_short) {
43             dbStatement.setShort(position, anyParam.extract_short());
44             J = TCKind.tk_short;
45         }
46        }
47        catch (Exception JavaDoc ex)
48        {
49         System.out.println("** AnyTypeTrans: <EXCEPTION> While putting data in the PreparedStatement");
50         System.out.println(ex.getMessage());
51        }
52
53        return J.value();
54
55     } // End of Method 'toDB'
56

57
58     /************************************************************************/
59     /* METHOD 'fromDB' */
60     /************************************************************************/
61     public Any JavaDoc fromDB(ResultSet rs, int L, int rsPosition) {
62
63         org.omg.CORBA.TCKind JavaDoc K = null;
64
65         K = TCKind.from_int(L);
66
67         Any JavaDoc res = org.objectweb.ccm.CORBA.TheORB.getORB().create_any();
68
69         try
70         {
71             if (K == TCKind.tk_string ) {
72                 String JavaDoc A = rs.getString(rsPosition);
73                 res.insert_string(A);
74             }
75
76             if (K == TCKind.tk_boolean ) {
77                 boolean B = rs.getBoolean(rsPosition);
78                 res.insert_boolean(B);
79             }
80             if (K == TCKind.tk_double ) {
81                 double C = rs.getDouble(rsPosition);
82                 res.insert_double(C);
83             }
84             if (K == TCKind.tk_float ) {
85                 float D = rs.getFloat(rsPosition);
86                 res.insert_float(D);
87             }
88             if (K == TCKind.tk_ulong ) {
89                 int E = rs.getInt(rsPosition);
90                 res.insert_ulong(E);
91             }
92             if (K == TCKind.tk_long ) {
93                 int F = rs.getInt(rsPosition);
94                 res.insert_long(F);
95             }
96             if (K == TCKind.tk_short ) {
97                 short G = rs.getShort(rsPosition);
98                 res.insert_short(G);
99             }
100         }
101         catch(Exception JavaDoc ex)
102         {
103             System.err.println("** AnyTypeTrans: <EXCEPTION> While getting data from the ResultSet");
104             System.err.println(ex.getMessage());
105
106         }
107
108         return res;
109
110     } // End of Method 'fromDB'
111

112 } // End of Class 'AnyTypeTrans'
113
Popular Tags