I'm a beginner in Server-side programming in java, and I wrote a sample program that fetches the records from a database table and prints them on the console. So, I created a table in the database with 3 columns of types INT, VARCHAR and FLOAT, and entered some data in it. In the JDBC code, the first two types of data have been fetched successfully, which are getInt(col) and getString(col), but the getFloat(col) is not returning anything, even though there is data present in the table. I've double-checked the types in the database but it was of no help.
If I try to write getFloat(col) method individually (i.e. not in a loop) it works perfectly fine.
while(rs.next()) { //"rs" is the ResultSet object
for(int i=1; i<=noc; i++) { // "noc" is rs.getColumnCount()
switch(rsmd.getColumnType(i)) { // "rsmd" is the ResultSetMetaData object
case Types.VARCHAR :
System.out.print(rs.getString(i));
break;
case Types.INTEGER :
System.out.print(rs.getInt(i));
break;
case Types.FLOAT :
System.out.print(rs.getFloat(i));
break;
}
System.out.println();
}
}
/*
If I write like below, it works fine
rs.next();
System.out.println(rs.getFloat(3));
but it doesn't work as in the above code
*/
I expect the output to be a full table of records, but what I get is a table with missing "FLOAT" type column data. I don't understand what wrong I was doing.