KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > odbc > OdbcPreparedStatement


1 package com.daffodilwoods.daffodildb.odbc;
2
3 import com.daffodilwoods.daffodildb.client.*;
4 import com.daffodilwoods.daffodildb.server.serversystem.*;
5 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*;
6 import com.daffodilwoods.database.utility.*;
7 import in.co.daffodil.db.jdbc.*;
8
9 public class OdbcPreparedStatement extends OdbcResultSet{
10   public OdbcPreparedStatement(){
11   }
12
13   public OdbcPreparedStatement(String JavaDoc path) {
14   }
15
16   public Object JavaDoc execute(Object JavaDoc objPrep,Object JavaDoc[] parameters) throws Exception JavaDoc{
17     try {
18       _PreparedStatement preparedStatement = (_PreparedStatement)objPrep;
19
20       Object JavaDoc obj = preparedStatement.execute(parameters);
21       if (obj != null &&
22           preparedStatement.getQueryType() == _PreparedStatement.queryexpression) {
23         RecordSet rs = new RecordSet();
24         rs.setSelectIterator( (_SelectIterator) obj);
25         _RecordSetBufferIterator rsbi = rs.getIterator();
26         obj = rsbi;
27       }
28       return obj;
29     }
30     catch (NullPointerException JavaDoc ex) {
31       throw ex;
32     }
33   }
34
35   public Object JavaDoc[] getOutParameters(Object JavaDoc result,int[] types)throws Exception JavaDoc {
36     CallResult callResult = (CallResult)result;
37     Object JavaDoc[] outParameters = (Object JavaDoc[])callResult.getOUTParameters();
38     if(outParameters != null){
39       for (int i = 0; i < outParameters.length; i++) {
40         if (outParameters[i] != null) {
41           outParameters[i] = Utilities.convertObject(outParameters[i], types[i]);
42         }
43       }
44     }
45     return outParameters;
46   }
47
48   public Object JavaDoc getResultFormCallResult(Object JavaDoc result) throws Exception JavaDoc{
49     CallResult callResult = (CallResult)result;
50     Object JavaDoc obj = callResult.getResult();
51     if (obj != null && obj instanceof _SelectIterator) {
52       RecordSet rs = new RecordSet();
53       rs.setSelectIterator( (_SelectIterator) obj);
54       _RecordSetBufferIterator rsbi = rs.getIterator();
55       obj = rsbi;
56     }
57     return obj;
58   }
59   public int getRowCount(Object JavaDoc obj) throws Exception JavaDoc {
60     if (obj != null ){
61       if (obj instanceof Number JavaDoc)
62         return ( (Number JavaDoc) obj).intValue();
63       if(obj instanceof _RecordSetBufferIterator)
64         return (((_RecordSetBufferIterator)obj).getRowCount());
65     }
66     return 0;
67   }
68
69   public int getQueryType(Object JavaDoc objPrep) throws Exception JavaDoc{
70     _PreparedStatement preparedStatement = (_PreparedStatement) objPrep;
71     return preparedStatement.getQueryType();
72   }
73
74   public int getParameterCount(Object JavaDoc objPrep) throws Exception JavaDoc{
75     _PreparedStatement preparedStatement = (_PreparedStatement) objPrep;
76     return preparedStatement.getParameterCount();
77   }
78
79   public int getParameterType(Object JavaDoc objPrep,int index) throws Exception JavaDoc{
80     _PreparedStatement preparedStatement = (_PreparedStatement) objPrep;
81     return preparedStatement.getParameterMetaData().getParameterDataType(index-1);
82   }
83
84
85   public Object JavaDoc getByteObject(byte val){
86     return new Byte JavaDoc(val);
87   }
88
89   public Object JavaDoc getShortObject(short val){
90     return new Short JavaDoc(val);
91   }
92   public Object JavaDoc getIntegerObject(int val){
93     return new Integer JavaDoc(val);
94   }
95   public Object JavaDoc getLongObject(long val){
96     return new Long JavaDoc(val);
97   }
98
99   public Object JavaDoc getDoubleObject(double val){
100     return new Double JavaDoc(val);
101   }
102
103   public Object JavaDoc getFloatObject(float val){
104     return new Float JavaDoc(val);
105   }
106
107   public Object JavaDoc getBooleanObject(boolean val){
108     return Utilities.getBooleanValue(val);
109   }
110
111   public Object JavaDoc getDateObject(int year , int month, int day) {
112      year = year - 1900;
113      month = month - 1;
114     return new java.sql.Date JavaDoc(year,month,day);
115   }
116
117   public Object JavaDoc getTimeObject(int hours, int minutes , int seconds) {
118     return new java.sql.Time JavaDoc(hours,minutes,seconds);
119   }
120
121   public Object JavaDoc getTimeStampObject(int year , int month, int day , int hours, int minutes , int seconds, int nanos){
122      year = year - 1900;
123      month = month - 1;
124      return new java.sql.Timestamp JavaDoc(year,month,day,hours,minutes,seconds,nanos);
125   }
126
127   public Object JavaDoc getColumnCharacteristicsFromPrep(Object JavaDoc obj) throws Exception JavaDoc {
128     return ( (_PreparedStatement) obj).getColumnCharacteristics();
129   }
130
131
132 }
133
Popular Tags