我计划使用雅虎财务csv api生成网址,以获得股票实时价格和时间.该网址如下http://download.finance.yahoo.com/d/quotes.csvs=%40%5YHOO,GOOG,MSFT,BAC&f=nsl1o&e=.csv,它返回一个包含4列的表格.
我使用jdbc将数据存储到Mysql,但始终存在错误:"没有为参数5指定值".代码如下:public class Quote_Saver {private void connection(){try {Class.forName("com.mysql.jdbc.Driver"); } catch(ClassNotFoundException e){e.printStackTrace(); }}
private String retrieveQuote() {
StringBuffer buf = new StringBuffer();
try {
URL page = new URL("http://download.finance.yahoo.com/d/quotes.csv?s=%40%5YHOO,GOOG,MSFT,BAC&f=nsl1o&e=.csv");
String line;
URLConnection conn = page.openConnection();
conn.connect();
InputStreamReader in = new InputStreamReader(conn.getInputStream());
BufferedReader data = new BufferedReader(in);
while ((line = data.readLine()) != null) {
buf.append(line + "\n");
}
} catch (MalformedURLException mue) {
System.out.println("Bad URL: " + mue.getMessage());
} catch (IOException ioe) {
System.out.println("IO Error:" + ioe.getMessage());
}
return …Run Code Online (Sandbox Code Playgroud)