Source Code Cross Referenced for JDBCPlotter.java in  » Chart » charting-0.94 » de » progra » charting » model » 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 » Chart » charting 0.94 » de.progra.charting.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         JOpenChart Java Charting Library and Toolkit
003:         Copyright (C) 2001  Sebastian Müller
004:         http://jopenchart.sourceforge.net
005:
006:         This library is free software; you can redistribute it and/or
007:         modify it under the terms of the GNU Lesser General Public
008:         License as published by the Free Software Foundation; either
009:         version 2.1 of the License, or (at your option) any later version.
010:
011:         This library is distributed in the hope that it will be useful,
012:         but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         Lesser General Public License for more details.
015:
016:         You should have received a copy of the GNU Lesser General Public
017:         License along with this library; if not, write to the Free Software
018:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:
020:         JDBCPlotter.java
021:         Created on 9. October 2002
022:         Based on SQLPlotter.java, created on 29. December 2001
023:         
024:         */
025:
026:        package de.progra.charting.model;
027:
028:        import java.sql.*;
029:        import java.util.ArrayList;
030:
031:        /**
032:         * The class is used to convert database queries into ChartDataModels.
033:         * You can initialize the Plotter with database parameters and afterwards
034:         * you can run consecutive queries resulting in a new database.
035:         */
036:        public class JDBCPlotter {
037:
038:            /** The SQL connection. */
039:            protected Connection conn;
040:
041:            /**
042:             * Creates a new JDBCPlotter using the given driver and URL.
043:             * @param jdbcDriver the fully qualified classname of the SQL driver class.
044:             * @param jdbcURL the URL of the JDBC database to connect to.
045:             * @param username the username for the JDBC resource
046:             * @param password the user's password
047:             */
048:            public JDBCPlotter(String jdbcDriver, String jdbcURL,
049:                    String username, String password)
050:                    throws JDBCPlotterException {
051:                try {
052:                    Class.forName(jdbcDriver);
053:                    conn = DriverManager.getConnection(jdbcURL, username,
054:                            password);
055:                } catch (Exception e) {
056:                    throw new JDBCPlotterException(
057:                            "Exception while creating a database connection.",
058:                            e);
059:                }
060:            }
061:
062:            /** 
063:             * Given a SQL query and the row titles this method creates a DefaultChartDataModel.
064:             * The columns are initialized with values starting from 0.
065:             * @param sqlQuery the SQL query to be performed
066:             * @param sqlRows the rows from the ResultSet which should be included in the ChartDataModel and which
067:             * will be used as the DataSet titles.
068:             */
069:            public DefaultChartDataModel createChartDataModelInstance(
070:                    String sqlQuery, String[] sqlRows)
071:                    throws JDBCPlotterException {
072:                return createChartDataModelInstance(sqlQuery, sqlRows, sqlRows);
073:            }
074:
075:            /** 
076:             * Given a SQL query and the row titles this method creates a DefaultChartDataModel.
077:             * The columns are initialized with values starting from 0.
078:             * @param sqlQuery the SQL query to be performed
079:             * @param sqlRows the rows from the ResultSet which should be included in the ChartDataModel
080:             * @param dataSets the DataSet titles which should be given to the ChartDataModel instead of the sqlRows titles
081:             */
082:            public DefaultChartDataModel createChartDataModelInstance(
083:                    String sqlQuery, String[] sqlRows, String[] dataSets)
084:                    throws JDBCPlotterException {
085:                try {
086:                    Statement stmt = conn.createStatement();
087:                    ResultSet sqlResult = stmt.executeQuery(sqlQuery);
088:
089:                    ArrayList model[] = new ArrayList[sqlRows.length];
090:                    ArrayList columnList = new ArrayList();
091:
092:                    for (int i = 0; i < model.length; i++) {
093:                        model[i] = new ArrayList();
094:                    }
095:
096:                    double x = 0.0;
097:                    while (sqlResult.next()) {
098:
099:                        columnList.add(new Double(x));
100:                        x += 1.0;
101:
102:                        for (int i = 0; i < sqlRows.length; i++) {
103:                            model[i].add(new Double(sqlResult
104:                                    .getDouble(sqlRows[i])));
105:
106:                        }
107:                    }
108:
109:                    Number[][] modelArray = new Number[model.length][];
110:
111:                    for (int i = 0; i < model.length; i++)
112:                        modelArray[i] = (Number[]) model[i]
113:                                .toArray(new Number[0]);
114:
115:                    double[] columns = new double[columnList.size()];
116:
117:                    for (int i = 0; i < columns.length; i++)
118:                        columns[i] = ((Double) columnList.get(i)).doubleValue();
119:
120:                    return new DefaultChartDataModel(modelArray, columns,
121:                            dataSets);
122:
123:                } catch (Exception e) {
124:                    throw new JDBCPlotterException(
125:                            "Exception while performing task.", e);
126:                }
127:            }
128:
129:            /** 
130:             * Given a SQL query and the row titles this method creates a DefaultChartDataModel.
131:             * The columns are initialized with values from columnRow.
132:             * @param sqlQuery the SQL query to be performed
133:             * @param columnRow the row from the ResultSet which should be taken as the column (x-axis) values
134:             * @param sqlRows the rows from the ResultSet which should be included in the ChartDataModel and which
135:             * will be used as the DataSet titles.
136:             */
137:            public DefaultChartDataModel createChartDataModelInstance(
138:                    String sqlQuery, String columnRow, String[] sqlRows)
139:                    throws JDBCPlotterException {
140:                return createChartDataModelInstance(sqlQuery, columnRow,
141:                        sqlRows, sqlRows);
142:            }
143:
144:            /** 
145:             * Given a SQL query and the row titles this method creates a DefaultChartDataModel.
146:             * The columns are initialized with values from columnRow.
147:             * @param sqlQuery the SQL query to be performed
148:             * @param columnRow the row from the ResultSet which should be taken as the column (x-axis) values
149:             * @param sqlRows the rows from the ResultSet which should be included in the ChartDataModel
150:             * @param dataSets the DataSet titles which should be given to the ChartDataModel instead of the sqlRows titles
151:             */
152:            public DefaultChartDataModel createChartDataModelInstance(
153:                    String sqlQuery, String columnRow, String[] sqlRows,
154:                    String[] dataSets) throws JDBCPlotterException {
155:                try {
156:                    Statement stmt = conn.createStatement();
157:                    ResultSet sqlResult = stmt.executeQuery(sqlQuery);
158:
159:                    ArrayList model[] = new ArrayList[sqlRows.length];
160:                    ArrayList columnList = new ArrayList();
161:
162:                    for (int i = 0; i < model.length; i++) {
163:                        model[i] = new ArrayList();
164:                    }
165:
166:                    while (sqlResult.next()) {
167:
168:                        columnList.add(new Double(sqlResult
169:                                .getDouble(columnRow)));
170:
171:                        for (int i = 0; i < sqlRows.length; i++) {
172:                            model[i].add(new Double(sqlResult
173:                                    .getDouble(sqlRows[i])));
174:
175:                        }
176:                    }
177:
178:                    Number[][] modelArray = new Number[model.length][];
179:
180:                    for (int i = 0; i < model.length; i++)
181:                        modelArray[i] = (Number[]) model[i]
182:                                .toArray(new Number[0]);
183:
184:                    double[] columns = new double[columnList.size()];
185:
186:                    for (int i = 0; i < columns.length; i++)
187:                        columns[i] = ((Double) columnList.get(i)).doubleValue();
188:
189:                    return new DefaultChartDataModel(modelArray, columns,
190:                            dataSets);
191:                } catch (Exception e) {
192:                    throw new JDBCPlotterException(
193:                            "Exception while performing task.", e);
194:                }
195:            }
196:
197:            /** 
198:             * Given a SQL query and the row titles this method creates a ObjectChartDataModel.
199:             * The columns are initialized with values from row columnRow.
200:             * @param sqlQuery the SQL query to be performed
201:             * @param columnRow the row from the ResultSet which should be taken as the column (x-axis) values
202:             * @param sqlRows the rows from the ResultSet which should be included in the ChartDataModel and which
203:             * will be used as the DataSet titles.
204:             */
205:            public ObjectChartDataModel createObjectChartDataModelInstance(
206:                    String sqlQuery, String columnRow, String[] sqlRows)
207:                    throws JDBCPlotterException {
208:                return createObjectChartDataModelInstance(sqlQuery, columnRow,
209:                        sqlRows, sqlRows);
210:            }
211:
212:            /** 
213:             * Given a SQL query and the row titles this method creates an ObjectChartDataModel.
214:             * The columns are initialized with values of row columnRow.
215:             * @param sqlQuery the SQL query to be performed
216:             * @param columnRow the row from the ResultSet which should be taken as the column (x-axis) values
217:             * @param sqlRows the rows from the ResultSet which should be included in the ChartDataModel
218:             * @param dataSets the DataSet titles which should be given to the ChartDataModel instead of the sqlRows titles
219:             */
220:            public ObjectChartDataModel createObjectChartDataModelInstance(
221:                    String sqlQuery, String columnRow, String[] sqlRows,
222:                    String[] dataSets) throws JDBCPlotterException {
223:                try {
224:                    Statement stmt = conn.createStatement();
225:                    ResultSet sqlResult = stmt.executeQuery(sqlQuery);
226:
227:                    ArrayList model[] = new ArrayList[sqlRows.length];
228:                    ArrayList columnList = new ArrayList();
229:
230:                    for (int i = 0; i < model.length; i++) {
231:                        model[i] = new ArrayList();
232:                    }
233:
234:                    while (sqlResult.next()) {
235:
236:                        columnList.add(sqlResult.getString(columnRow));
237:
238:                        for (int i = 0; i < sqlRows.length; i++) {
239:                            model[i].add(new Double(sqlResult
240:                                    .getDouble(sqlRows[i])));
241:
242:                        }
243:                    }
244:
245:                    Number[][] modelArray = new Number[model.length][];
246:
247:                    for (int i = 0; i < model.length; i++)
248:                        modelArray[i] = (Number[]) model[i]
249:                                .toArray(new Number[0]);
250:
251:                    String[] columns = (String[]) columnList
252:                            .toArray(new String[0]);
253:
254:                    return new ObjectChartDataModel(modelArray, columns,
255:                            dataSets);
256:                } catch (Exception e) {
257:                    throw new JDBCPlotterException(
258:                            "Exception while performing task.", e);
259:                }
260:            }
261:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.