/*
______________________________________________________________________
*
* Copyright (c) 1996-2004, QUEST SOFTWARE INC. All Rights Reserved.
* http://java.quest.com
*
* This file is provided for demonstration and educational uses only.
* Permission to use, copy, modify and distribute this file for
* any purpose and without fee is hereby granted, provided that the
* above copyright notice and this permission notice appear in all
* copies, and that the name of Quest Software not be used in advertising
* or publicity pertaining to this material without the specific,
* prior written permission of an authorized representative of
* Quest Software.
*
* QUEST SOFTWARE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
* OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. QUEST SOFTWARE SHALL NOT BE LIABLE FOR ANY
* DAMAGES SUFFERED BY USERS AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
* ______________________________________________________________________
*/

//   RCSID -- $RCSfile: JDBC3dChart.java,v $ $Revision: 1.1.1.1 $
//           $Date: 2006-03-09 22:09:06 $  $Locker:  $  Quest Software Inc.
package examples.chart3d.j3d.data;

import com.klg.jclass.chart3d.data.JDBC3dDataSource;
import com.klg.jclass.util.swing.JCExitFrame;
import examples.chart3d.j3d.BaseExample;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * This is a basic example which demonstrates using a JDBC3dResultSet
 *  to populate a Chart3d.
 */
public class JDBC3dChart extends BaseExample {

public JDBC3dChart()
{
    this("JDBC Datasource");
}

public JDBC3dChart(String title)
{
    super(title);
}

public void init()
{
    super.init();
}

public void initData()
{
    ResultSet resultSet = null;

    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection conn = DriverManager.getConnection("jdbc:odbc:JClassDemo");
        PreparedStatement ps = conn.prepareStatement("SELECT * FROM Bonds");

        resultSet = ps.executeQuery();

        String[] columnNames = {"OriginalInterestRate", "CurrentYield"};

        JDBC3dDataSource ds = new JDBC3dDataSource(resultSet, "BondID",
                                                   "BondName", columnNames);
        getDataView().setElevationDataSource(ds);
    }
    catch (Exception e) {
        showErrorMessage(e.toString(), "Default Chart3D will be shown",
                         "SQL error");
    }
}

public static void main(String args[])
{
    JDBC3dChart example = null;
    example = new JDBC3dChart();
    final JCExitFrame frame = new JCExitFrame(example.getTitle());
    frame.getContentPane().add(example);

    frame.pack();
    frame.show();
    example.updateChart3d();
}

}
