Results 1 to 2 of 2

Thread: ParseInt fails, but ParseFloat works [Resolved]

  1. #1

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Thumbs up ParseInt fails, but ParseFloat works [Resolved]

    Hi,
    I am retrieving a resultset from a database.
    Then I assign the values to a String Array. Later when I try to parse the values of this array into an integer, it fails.
    However the parseFloat works.

    Any reasons? I am not bothered with the precision, since I know the count of records wont be in decimals.

    Here is my code..

    It fails where if I change the parseFloat to parseInt. I also changed the float Total[] to int Total[] when I did the parseInt.


    Code:
    import java.sql.*;
    import java.util.*;
    class ProcessedContracts{
    	public static void main(String [] args)
    	{
    	 try
    	 {	
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection Cn = DriverManager.getConnection("jdbc:odbc:DATADB","sa","password99!");
    	 ResultSet rs;
    	 StringBuffer strOut = new StringBuffer();
    	 float Total [] = new float[6];
    	 String rsHolder[] = new String[7];
    	 String strSQL = "SELECT SUM(DR1) '<=3', SUM(DR2) '4-5', SUM(DR3) '6-10',SUM(DR4) '11-20', SUM(DR5) '21-30', SUM(DR6) '>30', COUNTRY FROM TEMPO GRoUP BY COUNTRY";
    	 Statement st2 = Cn.createStatement();
    	 st2.executeUpdate("Create Table #TEMPO(COUNTRY varchar(32), DR1 int default 0, DR2 int default 0,DR3 int default 0,DR4 int default 0, DR5 int default 0, DR6 int default 0)");
    	 st2.executeUpdate("Execute TESTQUICKFIX");
    	 
    	 Statement st = Cn.createStatement();
    	 try
    	 {
    	 rs = st.executeQuery(strSQL);
    	 while(rs.next())
    	 {
    	 	rsHolder[0] = rs.getString(1);
    		rsHolder[1] = rs.getString(2);
    	 	rsHolder[2] = rs.getString(3);
    		rsHolder[3] = rs.getString(4);
    	 	rsHolder[4] = rs.getString(5);
    		rsHolder[5] = rs.getString(6);
    		rsHolder[6] = rs.getString(7);
    		 strOut.append("<tr>");
    		 for(int i = 0;i<=6;i++)
    		 {
    		  // System.out.println("Val of i --> " + i);
    		  // System.out.println("Val of rsHolder --> " +rsHolder[i]);
    			strOut.append("<td align='right' bgcolor='#ffefd5'>" + rsHolder[i] + "</td>");
    			strOut.append((char)10);
    		 }
    		 strOut.append("</tr>");
    		 for(int i=0;i<=5;i++)
    		 {
    		 	Total[i] += Float.parseFloat(rsHolder[i]);
    		 }
    	 }	 
    
    		/*
    		Total[0] += Integer.parseInt(rsHolder[0]);
    		Total[1] += Integer.parseInt(rsHolder[1]);
    		Total[2] += Integer.parseInt(rsHolder[2]);
    		Total[3] += Integer.parseInt(rsHolder[3]);
    		Total[4] += Integer.parseInt(rsHolder[4]);
    		Total[5] += Integer.parseInt(rsHolder[5]);
    		*/
    		strOut.append("<tr>");
    		strOut.append("<td align='right'>" + Total[0] + "</td>");
    		strOut.append("<td align='right'>" + Total[1] + "</td>");		
    		strOut.append("<td align='right'>" + Total[2] + "</td>");		
    		strOut.append("<td align='right'>" + Total[3] + "</td>");		
    		strOut.append("<td align='right'>" + Total[4] + "</td>");				
    		strOut.append("<td align='right'>" + Total[5] + "</td>");						
    		strOut.append((char)10);
    		strOut.append("<td align='right'>Total</td>");						
    		strOut.append("</tr>");
    		strOut.append((char)10);
    	 	st.executeUpdate("Drop Table #Tempo");
    	 	System.out.println(strOut);
    		}
    		catch(Exception ex)
    		{
    			System.out.println("SOME EXP");
    			System.out.println(ex.getMessage());
    		}
    		 
    	 }
    	 catch(Exception ec)
    	 {
    	   System.out.println("Exception Raised");
    	 	System.out.println(ec.getMessage());
    	 }
    	}
    }
    Cheers!
    Abhijit
    Last edited by abhijit; Mar 18th, 2003 at 11:25 PM.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  2. #2

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Exclamation


    Hi All,
    This was resolved. It got resolved after changing the ODBC DSN Connection Settings through the windows control panel.

    If any of you face such a problem, check the DSN Settings.

    Cheers!
    Abhijit
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

Posting Permissions

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



Click Here to Expand Forum to Full Width