HI All,
Another Question:
I have created another program that queries the StockTracker database for all users and the stocks held by each user. The program compiles, but at run-time i get the error:
"Exception in thread 'main' java.sql.SQLException: Column not found at sun.jdbc.odbc.JdbcOdbcResultSet.findColumn<JdbcOdbcResultSet.java:1833>
at sun.jdbc.odbc.JdbcOdbcResultSet.getString<JdbcOdbcResultSet.java:395>
at StockByUser.main<StockByUser.java:43>"
I am using the column names that are located in my database. Why is my program not picking up on them? It seems that my error is in the last println statement of my code. Should I not be using the getString() method here?
I am attaching my code as well:
import java.io.*;
import java.sql.*;
public class StockByUser
{
public static void main(String[] args)throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:StockTracker";
Connection con = DriverManager.getConnection(url);
Statement stmt = con.createStatement();
Statement stmt1 = con.createStatement();
Statement stmt2 = con.createStatement();
System.out.println("Stock holdings by User\n");
System.out.println("User ID User Name");
System.out.println(" Stock - Description");
System.out.println("-------------------------------------------");
ResultSet rs = stmt.executeQuery("SELECT * FROM Users ORDER BY userID");
ResultSet rs1 = stmt1.executeQuery("SELECT * FROM UserStocks ORDER BY userID");
ResultSet rs2 = stmt2.executeQuery("SELECT * FROM Stocks ORDER BY symbol");
String previousUser = null;
String currentUser = null;
while(rs.next())
{
currentUser = rs.getString("userID");
if (previousUser == null || !previousUser.equals(currentUser))
{
System.out.println(currentUser+" "+rs.getString("firstName")+" "+rs.getString("lastName"));
previousUser = currentUser;
}
System.out.println("\t"+rs.getString("symbol")+" "+rs.getString("name"));
}
}
}