Two Laptop Bag
The moose likes JDBC and Relational Databases and the fly likes how Can I fix this problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "how Can I fix this problem" Watch "how Can I fix this problem" New topic

how Can I fix this problem

Sohail Mahmood

Joined: May 20, 2004
Posts: 1
I have database in MS-ACCESS and have following values in the "column1" of "table1".


I write the following code in JSP

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

<% while( {

it is showing me the following Values

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33108

Welcome to Javaranch! You want to use rs.getDouble() instead. With getInt(), it is truncating your output to fit it into an integer.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
michael yue
Ranch Hand

Joined: Nov 20, 2003
Posts: 204
I face a problem when using getDouble like

<% while(

How do I assign rs.getDouble("column1") to a variable?
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.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

Moving to the JDBC forum.

[Asking smart questions] [About Bear] [Books by Bear]
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
ResultSet.getDouble() methods return a double not a Double.
What kind of error are you getting when you do the rs.getDouble("column1")?

Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
michael yue
Ranch Hand

Joined: Nov 20, 2003
Posts: 204
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

Joined: Nov 20, 2003
Posts: 204
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");
amount = amount.trim();
amount = "0";

Double Damount = Double.valueOf(amount);
double damt = (Damount.doubleValue()) ;
amount = String.valueOf(damt);
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572

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;
I agree. Here's the link:
subject: how Can I fix this problem
It's not a secret anymore!