Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how Can I fix this problem

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have database in MS-ACCESS and have following values in the "column1" of "table1".

column1
-------
0.1234
0.2345
1.1233

I write the following code in JSP
---------------------------------

String query1 = "SELECT column1 FROM table1";
ResultSet rs = stmt.executeQuery(query1);

<% while(rs.next()) {
out.println(rs.getInt("column1");
}
%>


it is showing me the following Values
-------------------------------------

0.0
0.0
1.0
 
author & internet detective
Posts: 41944
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sohail,
Welcome to Javaranch! You want to use rs.getDouble() instead. With getInt(), it is truncating your output to fit it into an integer.
 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I face a problem when using getDouble like

<% while(rs.next())
{out.println(rs.getDouble("column1");}%>

How do I assign rs.getDouble("column1") to a variable?
Using
double var = rs.getDouble("column1") and
Double var = rs.getDouble("column1")
gives error.
I know Double is a class so have to change from double to Double first. I am getting confused here.

Anyway initializing double also a problem like
double var = 0; -->gives error int found instead of double
How can I initialize double?

Now I have to be content with grabbing the data in String then convert it to double only then display it.
Thanks
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the JDBC forum.
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ResultSet.getDouble() methods return a double not a Double.
What kind of error are you getting when you do the rs.getDouble("column1")?
 
michael yue
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I mean I am having difficulties trying to initialize a double value. I declare
double x = 0; returns error int found instead of double.

So how can I initialize a double before assigning it to getDouble ?
 
michael yue
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is something that i forget to add.

This is what i am doing now to get a double value.

String amount = rst.getString("amount");
if(amount!=null)
amount = amount.trim();
else
amount = "0";

Double Damount = Double.valueOf(amount);
double damt = (Damount.doubleValue()) ;
amount = String.valueOf(damt);
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Why are you trying to get the double value in String? rs.getDouble() method return double not Double. What is the datatype of the column for which you are using getDouble() method?

You can initialize a double as
double d = 0.0d;
 
This tiny ad will self destruct in five seconds.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic