I am new to mysql and am having a problem updating my sql database from my java program.My java program performs all the calculations and stores the values to be updated in a string array of size 2000.My sql database contains the following columns
name price high low
my string array stores the price, high,low which are separated by commas.(I actually queried yahoo finance and stored the csv file in a string).
Now i need to update the price,high,low using the data in the string.How do i do it. Or is it possible to directly upload the data returned from yahoo finance into my database.
Code
URL yahoofin = new URL("http://finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=nl1sjkm3m4r");
URLConnection yc = yahoofin.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
}
The code i am using to update a single stock
Statement stmt = conn.createStatement() ;
// Execute the Update
int rows = stmt.executeUpdate( "UPDATE tablename SET id = 9842 WHERE name='name'" )
Construct a prepared statement:
Then iterate through the line of the CSV file, and parse each line into a data structure (or a simple array) containing the 4 fields:
And for each line, bind the parameters and execute the statement:
To speed up things, you may use a batch: