Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 48
  1. #21
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    I'm guessing the column that's not found is one of "stockSymbol", "shares", and "price". Ie one of these is not the actual name of a column.

    If you can get at the database from the command line or some other app you could try issuing the same sql query and seeing if the error message is more helpful and tells you which one is wrong.

    Where did you get these column names from anyway? Check their spelling and case. Make them exactly what they're supposed to be.

  2. #22
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    if i remove the lines with the arrows in the code below, the error goes away.......

    Java Code:
    private void displayStockData ( String stockName )
    	{
    		//display stock name, stock symbol, shares and price
    		try
    		{
    			//get stock name, stock symbol and shares
    			myResultSet = myStatement.executeQuery( "SELECT stockSymbol, "
    				+ " shares, price FROM stockInformation WHERE " +
    				"stockName = '" + ( stockName ) + "'" );
    			
    			// non empty result
    			if (myResultSet.next () )
    			{
    				stockNameJTextField.setText(  <<<<<<<<<<<<<<<<<<
    					myResultSet.getString( "stockName" ) ); <<<<<<<<<<<
    				stockSymbolJTextField.setText(
    					myResultSet.getString( "stockSymbol" ) );
    				sharesJTextField.setText(
    					myResultSet.getString( "shares" ) );
    					
    				DecimalFormat price = new DecimalFormat( "$0.00" );
    				
    				priceJTextField.setText(	
    					myResultSet.getString( "price" ) );
    			}
    			
    			myResultSet.close(); // close myResultSet
    HOWEVER that text box is obviously empty.

    also the "total text box is currently empty as well, but i THINK i can fix that.

  3. #23
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    if i better understood reading the stack trace i could try some things, but im not really sure what im reading....

    The stack trace tells you where the exception occured (ie what method), then what method called that, and what method called that one etc. I find a good start is to read down until I hit the first line that mentions my code.

    In this case it would be

    at StockPortfolio.displayStockData(StockPortfolio.jav a:288)

    I'm guessing line 288 is the one that executes the sql query.

    Hang on! In writing this I have just realised something. The following - or something like it - is the method you are using:

    Java Code:
    private void displayStockData ( String stockName )
    {
        //display stock name, stock symbol, shares and price
        try
        {
            //get stock name, stock symbol and shares
            myResultSet = myStatement.executeQuery( "SELECT [b]stockSymbol[/b],"
                    + " [b]shares[/b], [b]price[/b] FROM stockInformation WHERE " +
                    "stockName = '" + ( stockName ) + "'");
    			
            // non empty result
            if (myResultSet.next () )
            {
                stockNameJTextField.setText(
                        myResultSet.getString( "[b]stockName[/b]" ) );
                stockSymbolJTextField.setText(
                        myResultSet.getString( "[b]stockSymbol[/b]" ) );
                sharesJTextField.setText(
                        myResultSet.getString( "[b]shares[/b]" ) );
    			
                DecimalFormat price = new DecimalFormat( "$0.00" );
    				
                priceJTextField.setText(	
                        myResultSet.getString( "[b]price[/b]" ) );
            }
    			
            myResultSet.close(); // close myResultSet
    			
    			
    			
        }
        catch ( SQLException exception )
        {
            exception.printStackTrace();
        }
    }// end method display stock data

    I'm wondering if line 288 isn't the line

    Java Code:
    stockNameJTextField.setText(
            myResultSet.getString( "stockName" ) );

    The point is you can't get something from a result set (like "stockName") unless it was one of the things you got from the database with the query. Ie, in this case, you can only get "stockSymbol", "shares" and "price" since these are the columns mentioned in the query.

    If you are sure there is a "stockName" column, add it to the query.

  4. #24
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    if i remove the lines with the arrows in the code below, the error goes away.......

    My post following yours attempts to explain this. If you want some data for the text field you will have to add "stockName" to your query (and reinstate those lines).

  5. #25
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    im down to two more minor (hopefully) problems....

    my price textbox is showing something like 65.2315 instead of $65.23

    and the total textbox isn't outputing anything...

    here are those lines of code. im missing something with the output portion of the computertotalvalue i think with outputting it to the totalJTExtbox, and as far as decimal format, i havent learned that yet, im just try to use it based off another example...

    Java Code:
     private void stockInfoJButtonActionPerformed( ActionEvent event )
       {
    	   // get selected stock
    	  String stockName = 
    	  	( String ) stockNamesJComboBox.getSelectedItem(); 
    	  	
    	  	//display stock data
    	  	displayStockData ( stockName );
    	  	
    	} // end method stockInfoJButtonActionPerformed
    	
    	//display stock information
    	private void displayStockData ( String stockName )
    	{
    		//display stock name, stock symbol, shares and price
    		try
    		{
    			//get stock name, stock symbol and shares
    			myResultSet = myStatement.executeQuery( "SELECT stockName, stockSymbol, "
    				+ " shares, price FROM stockInformation WHERE " +
    				"stockName = '" + ( stockName ) + "'" );
    			
    			// non empty result
    			if (myResultSet.next () )
    			{
    				stockNameJTextField.setText(
    					myResultSet.getString( "stockName" ) );
    				stockSymbolJTextField.setText(
    					myResultSet.getString( "stockSymbol" ) );
    				sharesJTextField.setText(
    					myResultSet.getString( "shares" ) );
    					
    				DecimalFormat price = new DecimalFormat( "$0.00" );
    				
    				priceJTextField.setText(	
    					myResultSet.getString( "price" ) );
    			}
    			
    			myResultSet.close(); // close myResultSet
    			
    			
    			
    		}
    		catch ( SQLException exception )
          	{
             	exception.printStackTrace();
          	}
    	}// end method display stock data
    	
    	// calculate total value
    	private String computeTotalValue( int shares, double price )throws SQLException
    	{
    		
    		//get shares and price
    		shares = myResultSet.getInt( "shares" );
    		price = myResultSet.getDouble( "price" );
    		
    		totalJTextField.setText(
    					myResultSet.getString( "dollars" ) );
    
    		
    		// define display format
    		DecimalFormat dollars = new DecimalFormat( "$0.00" );
    		
    		totalJTextField.setText(
    					myResultSet.getString( "dollars" ) );
    
    		return dollars.format( shares * price );
    		
    		
    
    	} // end method computeTotalValue

  6. #26
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    my price textbox is showing something like 65.2315 instead of $65.23
    Java Code:
    DecimalFormat price = new DecimalFormat( "$0.00" );
    				
    priceJTextField.setText(	
            myResultSet.getString( "price" ) );

    You are getting the price as a string. What happens if you get it as a double instead (with getDouble()) and then actually apply the decimal format? (with format())

    Java Code:
    DecimalFormat priceFmt = new DecimalFormat( "$0.00" );
    double price = // get "price" as a double
    priceJTextField.setText(/*use priceFmt to format price*/);

    the total textbox isn't outputing anything...

    Yes you have a method for calculating the total price but you don't actually call it anywhere. (I think I mentioned this when you were dealing with the exception and returning a string.) So basically whereever you want to update the text field call this method and set the text field's text to whatever it returns.

    As you have written it that method looks a little odd. You pass it two arguments - shares and price - and then throw those values away and get the values from the result set. Do one thing or the other: That is either get rid of the parameters, or get rid of the getInt() and getDouble() lines.

    Since you have already figured out the price in the other method the second option might make more sense. (But if you do this the other method will have to change slightly because you don't actually have a variable representing the number of "shares".)

  7. #27
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    i have the decimal formatting part figured out now (thank you).

    i am still not able to get text to show up in the totalJTextBox though, and i know my computetotalvalue method is not right. i see the points you are making about "doing one thing or the other" i have tried a bunch of changes to see what will work, and still have not had any luck getting ANY sort of output. ill post JUST that method, and see if you could help me get this project wrapped up. thank you!
    Java Code:
    private String computeTotalValue( int shares, double price )throws SQLException
    	{
    		
    		//get shares and price
    		shares = myResultSet.getInt( "shares" );
    		price = myResultSet.getDouble( "price" );
    
    		// define display format
    		DecimalFormat dollars = new DecimalFormat( "$0.00" );
    
    		return dollars.format( shares * price );
    		
    		
    		
    
    	} // end method computeTotalValue

  8. #28
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    i have tried re-wording and changing the ways the variables are shown, the setText wording, added a String total, and various other things, and can't seem to get anything to output.....

  9. #29
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Did you understand what I meant by saying that you don't call this method anywhere?

    (And is my statement still true? The code has changed somewhat.)

    The point is that just having a method computeTotalValue() - and that method is OK as it is, just a bit wierd - will not itself cause the total value to get calculated. It only does the calculation if you call the method from somewhere else in the program.

    So think about where (or when) you expect the total value text field to get updated. And at that point in your code call the computeTotalValue() method.

  10. #30
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Put another way: if you want the total value to show up in your GUI you must have a line like

    Java Code:
    totalJTextField.setText(/*???*/);

    somewhere in your code. And it probably won't be in the calculateTotalValue() method. It will be whereever the other text fields get their text set.

  11. #31
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    i have, i have tried this:

    totalJTextField.setText ( computeTotalValue() ); and put it in the "display stock data method, but i get an error, like this:
    Java Code:
    c:\SimplyJava\StockPortfolio>javac StockPortfolio.java
    StockPortfolio.java:311: computeTotalValue(int,double) in StockPortfolio cannot
    be applied to ()
            totalJTextField.setText ( computeTotalValue() );
                                      ^
    1 error
    so i changed the line to this:

    totalJTextField.setText ( computeTotalValue(shares,price) );

    but i get this error:
    Java Code:
    c:\SimplyJava\StockPortfolio>javac StockPortfolio.java
    StockPortfolio.java:311: cannot find symbol
    symbol  : variable shares
    location: class StockPortfolio
            totalJTextField.setText ( computeTotalValue(shares,price) );
                                                        ^
    StockPortfolio.java:311: cannot find symbol
    symbol  : variable price
    location: class StockPortfolio
            totalJTextField.setText ( computeTotalValue(shares,price) );
                                                               ^
    2 errors

  12. #32
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    so then i reworded the compute total value method to this:

    Java Code:
    private String computeTotalValue()throws SQLException
    	{
    		int shares;
    		double price;
    		//get shares and price
    		shares = myResultSet.getInt( "shares" );
    		price = myResultSet.getDouble( "price" );
    
    		// define display format
    		DecimalFormat dollars = new DecimalFormat( "$0.00" );
    
    		return dollars.format( shares * price );
    		
    		
    	} // end method computeTotalValue
    and changed the call to the method back to this:

    Java Code:
    totalJTextField.setText ( computeTotalValue() );
    and i get this error:
    c:\SimplyJava\StockPortfolio>javac StockPortfolio.java
    StockPortfolio.java:311: unreported exception java.sql.SQLException; must be cau
    ght or declared to be thrown
    totalJTextField.setText ( computeTotalValue() );
    ^
    1 error

  13. #33
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    this is kind of where i am at the moment......
    although with numerous attempts in between....

    Java Code:
    private void displayStockData ( String stockName )
    	{
    		//display stock name, stock symbol, shares and price
    		try
    		{
    			//get stock name, stock symbol and shares
    			myResultSet = myStatement.executeQuery( "SELECT stockName, stockSymbol, "
    				+ " shares, price FROM stockInformation WHERE " +
    				"stockName = '" + ( stockName ) + "'" );
    			
    			// non empty result
    			if (myResultSet.next () )
    			{
    				stockNameJTextField.setText(
    					myResultSet.getString( "stockName" ) );
    				stockSymbolJTextField.setText(
    					myResultSet.getString( "stockSymbol" ) );
    				sharesJTextField.setText(
    					myResultSet.getString( "shares" ) );
    					
    				DecimalFormat priceFmt = new DecimalFormat( "$0.00" );
    				double price = myResultSet.getDouble ( "price" );
    				priceJTextField.setText( priceFmt.format (price) );	
    				
    				
    			}
    			
    			myResultSet.close(); // close myResultSet
    			
    			
    		}
    		catch ( SQLException exception )
          	{
             	exception.printStackTrace();
          	}
          	
          	totalJTextField.setText ( computeTotalValue() );
    
    	}// end method display stock data
    	
    	// calculate total value
    	private String computeTotalValue()throws SQLException
    	{
    		int shares;
    		double price;
    		//get shares and price
    		shares = myResultSet.getInt( "shares" );
    		price = myResultSet.getDouble( "price" );
    
    		// define display format
    		DecimalFormat dollars = new DecimalFormat( "$0.00" );
    
    		return dollars.format( shares * price );
    		
    		
    	} // end method computeTotalValue

  14. #34
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Since you have an uncaught exception, what happens if you move the totalJTextField.setText() line into (at the end of) the try block?

    [Edit] In fact, if you think about it, it must come before you close the result set.

  15. #35
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    if i do that it compiles, but i get a stack trace error, and no output in the totalJTextBox.

  16. #36
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    the stack trace error:

    Java Code:
    c:\SimplyJava\StockPortfolio>java StockPortfolio sun.jdbc.odbc.JdbcOdbcDriver jd
    bc:odbc:stocks
    java.sql.SQLException: No data found
            at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7138)
            at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(JdbcOdbc.java:3811)
            at sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(JdbcOdbcResultSet.java
    :5638)
            at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:583)
            at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:601)
            at StockPortfolio.computeTotalValue(StockPortfolio.java:320)
            at StockPortfolio.displayStockData(StockPortfolio.java:299)
            at StockPortfolio.stockInfoJButtonActionPerformed(StockPortfolio.java:27
    0)
            at StockPortfolio.access$000(StockPortfolio.java:9)
            at StockPortfolio$1.actionPerformed(StockPortfolio.java:121)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:19
    95)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
    a:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
    .java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242
    )
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
    istener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6267)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6032)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577
    )
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2478)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
    ad.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
    java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

  17. #37
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    also, to clarify, if i move it into the if statement that is IN the try statment i get the error listed above, if i move it into the try statement, but after the if{} portion, i get a "Result set is closed" stack trace

  18. #38
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    Quote Originally Posted by pbrockway2 View Post
    Since you have an uncaught exception, what happens if you move the totalJTextField.setText() line into (at the end of) the try block?

    [Edit] In fact, if you think about it, it must come before you close the result set.
    with this:
    Java Code:
    private void displayStockData ( String stockName )
    	{
    		//display stock name, stock symbol, shares and price
    		try
    		{
    			//get stock name, stock symbol and shares
    			myResultSet = myStatement.executeQuery( "SELECT stockName, stockSymbol, "
    				+ " shares, price FROM stockInformation WHERE " +
    				"stockName = '" + ( stockName ) + "'" );
    			
    			// non empty result
    			if (myResultSet.next () )
    			{
    				stockNameJTextField.setText(
    					myResultSet.getString( "stockName" ) );
    				stockSymbolJTextField.setText(
    					myResultSet.getString( "stockSymbol" ) );
    				sharesJTextField.setText(
    					myResultSet.getString( "shares" ) );
    					
    				DecimalFormat priceFmt = new DecimalFormat( "$0.00" );
    				double price = myResultSet.getDouble ( "price" );
    				priceJTextField.setText( priceFmt.format (price) );	
    				
    				
    			
    				
    			}
    			totalJTextField.setText ( computeTotalValue() );
    			
    			myResultSet.close(); // close myResultSet
    			
    			
    		}
    		catch ( SQLException exception )
          	{
             	exception.printStackTrace();
          	}
          
    	}// end method display stock data
    	
    	// calculate total value
    	private String computeTotalValue()throws SQLException
    	{
    		int shares;
    		double price;
    		//get shares and price
    		shares = myResultSet.getInt( "shares" );
    		price = myResultSet.getDouble( "price" );
    
    		// define display format
    		DecimalFormat dollars = new DecimalFormat( "$0.00" );
    
    		return dollars.format( shares * price );
    		
    		
    	} // end method computeTotalValue
    then i get this error:
    Java Code:
    c:\SimplyJava\StockPortfolio>java StockPortfolio sun.jdbc.odbc.JdbcOdbcDriver jd
    bc:odbc:stocks
    java.sql.SQLException: No data found
            at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7138)
            at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(JdbcOdbc.java:3811)
            at sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(JdbcOdbcResultSet.java
    :5638)
            at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:583)
            at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:601)
            at StockPortfolio.computeTotalValue(StockPortfolio.java:322)
            at StockPortfolio.displayStockData(StockPortfolio.java:303)
            at StockPortfolio.stockInfoJButtonActionPerformed(StockPortfolio.java:27
    0)
            at StockPortfolio.access$000(StockPortfolio.java:9)
            at StockPortfolio$1.actionPerformed(StockPortfolio.java:121)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:19
    95)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
    a:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
    .java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242
    )
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
    istener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6267)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6032)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4630)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577
    )
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2478)
            at java.awt.Component.dispatchEvent(Component.java:4460)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
    ad.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
    java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

  19. #39
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    For myResultSet to make sense the call to computeTotalValue() must come after myResultSet.next() and before myResultSet.close(). ie inside the if block where you have it.

    Java Code:
    c:\SimplyJava\StockPortfolio>java StockPortfolio sun.jdbc.odbc.JdbcOdbcDriver jd
    bc:odbc:stocks
    java.sql.SQLException: No data found
            at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7138)
            at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(JdbcOdbc.java:3811)
            at sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(JdbcOdbcResultSet.java
    :5638)
            at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:583)
            at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:601)
            [b]at StockPortfolio.computeTotalValue(StockPortfolio.java:320)[/b]

    Line 320 is "shares = myResultSet.getInt( "shares" );", right?

    Is the "shares" value a valid integer? You can check this by commenting out the computeTotalValue() call, running the program and having a look at what is displayed in in the shares text field. It should be a valid integer: ie no decimal point or spaces.

    What happens if you replace the getInt() line with

    Java Code:
    shares = Integer.parseInt(myResultSet.getString("shares"));

    ? (Again the point is to see if there is any data there - even data which is not a valid integer for some reason.)

  20. #40
    hayden06f4i is offline Senior Member
    Join Date
    Oct 2010
    Posts
    119
    Rep Power
    0

    Default

    my latest attempt, still getting errors, i have tried 5 other things in between......always getting a Data Not found error. so i tried moving the shares and price variables up before the results close.....still the same error....here is my latest code.


    Java Code:
    private void displayStockData ( String stockName )
    	{
    		//display stock name, stock symbol, shares and price
    		try
    		{
    			//get stock name, stock symbol and shares
    			myResultSet = myStatement.executeQuery( "SELECT stockName, stockSymbol, "
    				+ " shares, price FROM stockInformation WHERE " +
    				"stockName = '" + ( stockName ) + "'" );
    			
    			// non empty result
    			if (myResultSet.next () )
    			{
    				stockNameJTextField.setText(
    					myResultSet.getString( "stockName" ) );
    				stockSymbolJTextField.setText(
    					myResultSet.getString( "stockSymbol" ) );
    				sharesJTextField.setText(
    					myResultSet.getString( "shares" ) );
    					
    				DecimalFormat priceFmt = new DecimalFormat( "$0.00" );
    				double price = myResultSet.getDouble ( "price" );
    				priceJTextField.setText( priceFmt.format (price) );	
    			}
    			
    			 int shares = Integer.parseInt (myResultSet.getString( "shares" ));
    			double price = Double.parseDouble (myResultSet.getString( "price") );
    		
    			totalJTextField.setText ( computeTotalValue(shares,price) );
    			
    			myResultSet.close(); // close myResultSet
    			
    			
    		}
    		catch ( SQLException exception )
          	{
             	exception.printStackTrace();
          	}
          
    	}// end method display stock data
    	
    	// calculate total value
    	private String computeTotalValue(int shares, double price)throws SQLException
    	{
    		
    		// define display format
    		DecimalFormat dollars = new DecimalFormat( "$0.00" );
    
    		return dollars.format( shares * price );
    		
    	} // end method computeTotalValue

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Have I done this exercise right?
    By ccie007 in forum New To Java
    Replies: 7
    Last Post: 09-28-2010, 06:54 PM
  2. Exercise for java 3d
    By armiri in forum Java 2D
    Replies: 2
    Last Post: 05-14-2010, 12:14 AM
  3. Exercise for java 3d
    By armiri in forum Java Software
    Replies: 3
    Last Post: 05-14-2010, 12:13 AM
  4. Help needed with Java exercise - Including arrays - Reward
    By TheDarkReverend in forum New To Java
    Replies: 7
    Last Post: 10-23-2008, 03:52 AM
  5. I/O exercise
    By Feldom in forum New To Java
    Replies: 1
    Last Post: 10-28-2007, 05:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •