0

I am writing a program to provide stock data to a GUI, which will update real time. When I use the Smart Tags in Excel, it updates with 13 columns: Last, Previous, Close, High, Low, Volume, Change, % Change, 52 Wk High, 52 Wk Low, Market Cap, EPS, P/E Ratio, and # Shares Out. However, I only want to deal with a few of the columns. Is there any way to only select a few of the columns to pull the data from? This is what I am using to pull the data and it works, but I don't want all of it:

try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection connect = DriverManager.getConnection("jdbc:odbc:Book1");
        Statement st = connect.createStatement();
        ResultSet result_set = st.executeQuery("SELECT * FROM A3:P30");
        ResultSetMetaData md = result_set.getMetaData();
        int columns = md.getColumnCount();
        for (int i = 1; i <= columns; i++) {
            columnNames.addElement(md.getColumnName(i));
        }
        while (result_set.next()) {
            Vector row = new Vector(columns);
            for (int i = 1; i <= columns; i++)
                row.addElement(result_set.getObject(i));
            data.addElement(row);
        }
        result_set.close();
        st.close();
    } catch (Exception e) {
        System.out.println(e);
    }

In Book1, I have 27 entries which is where P30 comes from.. Thank you, in advance!

Vincent Giuliana
  • 113
  • 1
  • 2
  • 8
  • what options have you tried? please mention here – Jatin Khurana Mar 25 '14 at 03:18
  • I've tried changing the query to `st.executeQuery("SELECT * FROM A, D, E, F")` and so on for the columns that I needed. Also, `st.executeQuery("SELECT * FROM #A3:A30, #D3:D30, #E3:E30, #F3:F30")` with the same columns. – Vincent Giuliana Mar 25 '14 at 03:47

1 Answers1

0

If you have an header line like Last, Previous, Close, High etc use

select [Last],[Previous],[Close],[High] from [SheetName$]

We are using the same code and works fine.

Luca Basso Ricci
  • 17,829
  • 2
  • 47
  • 69
  • The problem with that is that when I refresh all of the data in Escel, the default headers come back looking like this: [this](http://postimg.org/image/9hqxsyprh/). So according to Excel, `Last`, `Previous Close`, etc. aren't actual headers. – Vincent Giuliana Mar 25 '14 at 14:10