Hi again folks. I have a function called "linearRegressi on()" now I am along way from finishing this function atm. A little about this function: The function executes an SQL query grabbing a column from a table in my database called "Yahoo". Now here is where things are getting fuzzy for me. I need to be able to perform mathematical operations on this result set ie. finding the rsquared value, slope, average etc..... but i cannot do any of this on the list at is is now. I have tried created the list as a "type specific" list, but for whatever reason eclipse is giving me errors. I have tried converting my list to doubles numerous times without any results. Any guidance is appreciated. -
public void linearRegression()
-
{
-
try
-
{
-
List list = new ArrayList();
-
result= db_statement.executeQuery("select Close from Yahoo");
-
System.out.println ("Query Successful");
-
-
while (result.next())
-
{
-
list.add(result.getString("close"));
-
}
-
System.out.println(list);
-
} catch (Exception excep) {
-
System.out.println ("Unable to execute query: n" + excep);
-
System.exit(0);
-
}
-
}
-
-
I have omitted all my failed methods of conversion as they were just confusing me further. I figured here would be a good place to ask for guidance. Thanks in advance.
Also is there any reason why creating a list of specific type would not work in Eclipse? i am using Eclipse 3.2 and my java is 1.6.02 (or whatever the most up todate version is)
12 2617
Hi again folks. I have a function called "linearRegressi on()" now I am along way from finishing this function atm. A little about this function: The function executes an SQL query grabbing a column from a table in my database called "Yahoo". Now here is where things are getting fuzzy for me. I need to be able to perform mathematical operations on this result set ie. finding the rsquared value, slope, average etc..... but i cannot do any of this on the list at is is now. I have tried created the list as a "type specific" list, but for whatever reason eclipse is giving me errors. I have tried converting my list to doubles numerous times without any results. Any guidance is appreciated. -
public void linearRegression()
-
{
-
try
-
{
-
List list = new ArrayList();
-
result= db_statement.executeQuery("select Close from Yahoo");
-
System.out.println ("Query Successful");
-
-
while (result.next())
-
{
-
list.add(result.getString("close"));
-
}
-
System.out.println(list);
-
} catch (Exception excep) {
-
System.out.println ("Unable to execute query: n" + excep);
-
System.exit(0);
-
}
-
}
-
-
I have omitted all my failed methods of conversion as they were just confusing me further. I figured here would be a good place to ask for guidance. Thanks in advance.
Also is there any reason why creating a list of specific type would not work in Eclipse? i am using Eclipse 3.2 and my java is 1.6.02 (or whatever the most up todate version is)
Is this giving any error in Eclipse?
And the Q. is not clear to me, what O/P you expect..please tell me in details :-)
Kind regards,
Dmjpro.
Sorry m8. No that current function gives me no errors. But I cannot perform math operations on it. for example:
double sum = list(0) + list(1);
will not work because the list elements are objects. I need a way to convert them to doubles... this is probably much easier then I am making it. But thus far repeated attempts have done nothing but "fog" up my code.
Sorry m8. No that current function gives me no errors. But I cannot perform math operations on it. for example:
double sum = list(0) + list(1);
will not work because the list elements are objects. I need a way to convert them to doubles... this is probably much easier then I am making it. But thus far repeated attempts have done nothing but "fog" up my code.
Don't use code words, it's a forum not a chatting room :-)
And be specific about your problem.
Are you sure that what you store in list that can be parsed as double?
Then have a look at this code. -
double sum = parseDouble(list.get(0)) + parseDouble(list(list.get(1));
-
Kind regards,
Dmjpro.
Thank you for your code, but it did not work "The method parseDouble(Obj ect) is undefined for the type JDBC". So I guess my list cannot be converted into a double?
I have tried - List<Integer> intlist = new ArrayList<Integer>();
but Eclipse gives me errors when I try to use the "<Integer>" or "<double>". So perhaps there is an alternative way to read my result set into something I can work with?
Thank you for your code, but it did not work "The method parseDouble(Obj ect) is undefined for the type JDBC". So I guess my list cannot be converted into a double?
I have tried - List<Integer> intlist = new ArrayList<Integer>();
but Eclipse gives me errors when I try to use the "<Integer>" or "<double>". So perhaps there is an alternative way to read my result set into something I can work with?
Sorry I made a mistake.
I am so sorry :-(
It will be Double.parseDou ble(String)
So I am rewriting the code. -
double sum = Double.parseDouble((String)list.get(0)) + Double.parseDouble((String)list(list.get(1));
-
Again I am so sorry :-(
Kind regards,
Dmjpro.
Success!!!
Thank you sir. Now i just need to figure out away to sum up all the records, but you have given me the ability to move forward.
Thanks again.
Success!!!
Thank you sir. Now i just need to figure out away to sum up all the records, but you have given me the ability to move forward.
Thanks again.
You are welcome buddy :-)
Come again whenever you have problem.
Please check your PM.
Kind regards,
Dmjpro.
If the values are type decimal in the database, then use - List<Double> list = new ArrayList<Double>();
to declare the arraylist.
Then use rs.getDouble() to retrieve them.
If the values are type decimal in the database, then use - List<Double> list = new ArrayList<Double>();
to declare the arraylist.
Then use rs.getDouble() to retrieve them.
Thank you r035198x (got it right this time:) ). I tried that way but for some odd reason Eclipse was giving me an error. I am using the next to newest version of Eclipse so perhaps that was the issue? Parsing the strings to doubles worked for the time being. My function is going to get far more complex so I might have to look at really finding the source of the error while using the method you suggested. But for now I shall plow ahead.
Thank you again for your advice.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Claire |
last post by:
I have a multidimensional array defined as
private double myArray = new double;
The first column of the array contains X values, the other contains Y values
I have a charting function defined as
Add(Array XValues, Array YValues)
How do I call the Add function, passing my array columns please.
thanks
|
by: Frederik Vanderhaeghe |
last post by:
Hi,
I have a problem converting text to a double. Why doesn't the code work:
If Not (txtdocbedrag.Text = "") Then
Select Case ddlBedrag.SelectedIndex
Case 0
Case 1
|
by: Tor Aadnevik |
last post by:
Hi,
I have a problem converting values from Single to double.
eg. When the Single value 12.19 is converted to double, the result is
12.1899995803833.
Anyone know how to avoid this?
Regards Totto
|
by: SMichal |
last post by:
Hi, how can I parse string "? 20.000" to double ?
|
by: Dilip |
last post by:
Recently in our code, I ran into a situation where were stuffing a
float inside a double. The precision was extended automatically
because of that. To make a long story short, this caused problems
elsewhere in another part of the system where that figure was used for
some calculation and some eventual truncation led to the system going
haywire. So my question is, given this code:
int main()
{
float f = 59.89F;
| |
by: Ron |
last post by:
I want to calculate the surface area of a sphere from an inputed radius
with option strict on. I guess I am not converting something
correctly.
Here is what I am doing:
I have a textbox txtradius that I enter a radius into.
I then have a lable that I want the surface area to be displayed in
called lblsurface
|
by: nvx |
last post by:
Hi,
I'm looking for a simple way to convert a Double to a String exactly
the .ToString() does, except these two differences:
- the number of decimals is given (rounding is applied if
necessary), and
- trailing zeroes are kept.
This means I need it to be converted using the scientific notation if
the number is greater than a certain value etc., not just a simple
"this number of digits (or more if needed) before the decimal point
|
by: curious2007 |
last post by:
I get this long and hard to understand warning when I call a constructor:
AssocArray<double, string> myAssocArray(names, myArr);
the code for the constructor:
template <class V, class AI, class I, class S>
AssocArray<V, AI, I, S>::AssocArray(const list<AI>& names, const Array<V, I, S>& source)
{
|
by: clintonb |
last post by:
Victor said:
The double value that I'm trying to convert to GCSMoney (which is
implemented as cents) was produced by multiplying a dollar amount by
an interest rate to get interest.
double amount = 126.60;
double interestRate = .075;
double interest = amount * interestRate;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |