Source Code Cross Referenced for ResultSetColumnReader.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » fw » sql » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.fw.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.fw.sql;
002:
003:        /*
004:         * Copyright (C) 2002-2003 Colin Bell
005:         * colbell@users.sourceforge.net
006:         * Copyright (C) 2002 Johan Compagner
007:         * jcompagner@j-com.nl
008:         *
009:         * This library is free software; you can redistribute it and/or
010:         * modify it under the terms of the GNU Lesser General Public
011:         * License as published by the Free Software Foundation; either
012:         * version 2.1 of the License, or (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
017:         * Lesser General Public License for more details.
018:         *
019:         * You should have received a copy of the GNU Lesser General Public
020:         * License along with this library; if not, write to the Free Software
021:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
022:         */
023:        import java.sql.Date;
024:        import java.sql.ResultSet;
025:        import java.sql.ResultSetMetaData;
026:        import java.sql.SQLException;
027:        import java.sql.Time;
028:        import java.sql.Timestamp;
029:        import java.sql.Types;
030:
031:        public class ResultSetColumnReader {
032:            /** Logger for this class. */
033:            //	private final static ILogger s_log =
034:            //		LoggerController.createLogger(ResultSetColumnReader.class);
035:            private final static Long LONG_ZERO = Long.valueOf(0);
036:            private final static Double DOUBLE_ZERO = Double.valueOf(0);
037:
038:            /** The <TT>ResultSet</TT> being read. */
039:            private final ResultSet _rs;
040:
041:            /** <TT>true</TT> if the last column read had a value of SQL NULL. */
042:            private boolean _wasNull;
043:
044:            /** Metadata for the <TT>ResultSet</TT>. */
045:            private ResultSetMetaData _rsmd;
046:
047:            public ResultSetColumnReader(ResultSet rs) throws SQLException {
048:                super ();
049:                if (rs == null) {
050:                    throw new IllegalArgumentException("ResultSet == null");
051:                }
052:
053:                _rs = rs;
054:                _rsmd = rs.getMetaData();
055:            }
056:
057:            /**
058:             * Position <TT>ResultSet</TT> to the next row.
059:             *
060:             * @return	<TT>true</TT> if there is a &quot;next row&quot; to read.
061:             *
062:             * @throws	SQLException	SQL error occured.
063:             */
064:            public boolean next() throws SQLException {
065:                return _rs.next();
066:            }
067:
068:            /**
069:             * Retrieve the specifed column as a <TT>Boolean</TT>.
070:             *
071:             * @param	columnIdx	Column index (starts at 1) of the column to be read.
072:             *
073:             * @return	Boolean value of the specified column.
074:             *
075:             * @throws	SQLException	SQL error occured.
076:             */
077:            public Boolean getBoolean(int columnIdx) throws SQLException {
078:                Object obj = _rs.getObject(columnIdx);
079:                Boolean results = Boolean.FALSE;
080:                _wasNull = true;
081:
082:                if (obj != null) {
083:                    final int columnType = _rsmd.getColumnType(columnIdx);
084:                    if (columnType != Types.NULL) {
085:                        _wasNull = false;
086:                        switch (columnType) {
087:                        // TODO: When JDK1.4 is the earliest JDK supported
088:                        // by Squirrel then remove the hardcoding of the
089:                        // boolean data type.
090:                        case Types.BIT:
091:                        case Types.BOOLEAN:
092:                            if (obj instanceof  Boolean) {
093:                                results = (Boolean) obj;
094:                            } else {
095:                                if (obj instanceof  Number) {
096:                                    if (((Number) obj).intValue() == 0) {
097:                                        results = Boolean.FALSE;
098:                                    } else {
099:                                        results = Boolean.TRUE;
100:                                    }
101:                                } else {
102:                                    results = Boolean.valueOf(obj.toString());
103:                                }
104:                            }
105:                            break;
106:
107:                        default:
108:                            results = Boolean.valueOf(obj.toString());
109:                            break;
110:                        }
111:                    }
112:                }
113:
114:                return results;
115:            }
116:
117:            /**
118:             * Retrieve the specifed column as a <TT>Date</TT>.
119:             *
120:             * @param	columnIdx	Column index (starts at 1) of the column to be read.
121:             *
122:             * @return	Time value of the specified column.
123:             *
124:             * @throws	SQLException	SQL error occured.
125:             */
126:            public Date getDate(int columnIdx) throws SQLException {
127:                final Date results = _rs.getDate(columnIdx);
128:                _wasNull = results == null;
129:                return results;
130:            }
131:
132:            /**
133:             * Retrieve the specifed column as a <TT>Double</TT>.
134:             *
135:             * @param	columnIdx	Column index (starts at 1) of the column to be read.
136:             *
137:             * @return	Double value of the specified column.
138:             *
139:             * @throws	SQLException	SQL error occured.
140:             */
141:            public Double getDouble(int columnIdx) throws SQLException {
142:                Object obj = _rs.getObject(columnIdx);
143:                Double results = DOUBLE_ZERO;
144:                _wasNull = true;
145:
146:                if (obj != null) {
147:                    final int columnType = _rsmd.getColumnType(columnIdx);
148:                    if (columnType != Types.NULL) {
149:                        _wasNull = false;
150:                        switch (columnType) {
151:                        case Types.DOUBLE:
152:                        case Types.FLOAT:
153:                        case Types.REAL:
154:                            if (obj instanceof  Number) {
155:                                results = ((Number) obj).doubleValue();
156:                            } else {
157:                                results = new Double(obj.toString());
158:                            }
159:                            break;
160:                        default:
161:                            results = new Double(obj.toString());
162:                            break;
163:                        }
164:                    }
165:                }
166:
167:                return results;
168:            }
169:
170:            /**
171:             * Retrieve the specifed column as a <TT>Long</TT>.
172:             *
173:             * @param	columnIdx	Column index (starts at 1) of the column to be read.
174:             *
175:             * @return	long value of the specified column.
176:             *
177:             * @throws	SQLException	SQL error occured.
178:             */
179:            public Long getLong(int columnIdx) throws SQLException {
180:                Object obj = _rs.getObject(columnIdx);
181:                Long results = LONG_ZERO;
182:                _wasNull = true;
183:
184:                if (obj != null) {
185:                    final int columnType = _rsmd.getColumnType(columnIdx);
186:                    if (columnType != Types.NULL) {
187:                        _wasNull = false;
188:                        switch (columnType) {
189:                        case Types.SMALLINT:
190:                        case Types.TINYINT:
191:                        case Types.INTEGER:
192:                        case Types.BIGINT:
193:                            if (obj instanceof  Number) {
194:                                results = ((Number) obj).longValue();
195:                            } else {
196:                                results = new Long(obj.toString());
197:                            }
198:                            break;
199:                        case Types.BIT:
200:                            if ("true".equalsIgnoreCase(obj.toString())) {
201:                                results = Long.valueOf(1);
202:                            } else {
203:                                results = Long.valueOf(0);
204:                            }
205:                            break;
206:                        default:
207:                            results = new Long(obj.toString());
208:                            break;
209:                        }
210:                    }
211:                }
212:
213:                return results;
214:            }
215:
216:            /**
217:             * Retrieve the specifed column as an object.
218:             *
219:             * @param	columnIdx	Column index (starts at 1) of the column to be read.
220:             *
221:             * @return	Object value of the specified column.
222:             *
223:             * @throws	SQLException	SQL error occured.
224:             */
225:            public Object getObject(int columnIdx) throws SQLException {
226:                final Object results = _rs.getObject(columnIdx);
227:                _wasNull = results == null;
228:                return results;
229:            }
230:
231:            /**
232:             * Retrieve the specifed column as a string.
233:             *
234:             * @param	columnIdx	Column index (starts at 1) of the column to be read.
235:             *
236:             * @return	String value of the specified column.
237:             *
238:             * @throws	SQLException	SQL error occured.
239:             */
240:            public String getString(int columnIdx) throws SQLException {
241:                final String results = _rs.getString(columnIdx);
242:                _wasNull = results == null;
243:                return results;
244:            }
245:
246:            /**
247:             * Retrieve the specifed column as a <TT>Time</TT>.
248:             *
249:             * @param	columnIdx	Column index (starts at 1) of the column to be read.
250:             *
251:             * @return	Time value of the specified column.
252:             *
253:             * @throws	SQLException	SQL error occured.
254:             */
255:            public Time getTime(int columnIdx) throws SQLException {
256:                final Time results = _rs.getTime(columnIdx);
257:                _wasNull = results == null;
258:                return results;
259:            }
260:
261:            /**
262:             * Retrieve the specifed column as a <TT>TimeStamp</TT>.
263:             *
264:             * @param	columnIdx	Column index (starts at 1) of the column to be read.
265:             *
266:             * @return	TimeStamp value of the specified column.
267:             *
268:             * @throws	SQLException	SQL error occured.
269:             */
270:            public Timestamp getTimeStamp(int columnIdx) throws SQLException {
271:                final Timestamp results = _rs.getTimestamp(columnIdx);
272:                _wasNull = results == null;
273:                return results;
274:            }
275:
276:            /**
277:             * Reports whether the last column read had a value of SQL NULL.
278:             *
279:             * @return	<TT>true</TT> if last column read was <TT>null</TT>.
280:             */
281:            public boolean wasNull() {
282:                return _wasNull;
283:            }
284:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.