?? simpledao.java
字號:
package com.shfe.mail;
import java.io.*;
import java.sql.*;
import java.util.*;
import com.shfe.mail.GraphBean;
public class SimpleDAO {
public double openPrice = 0.0;
public double closePrice = 0.0;
public String title = "";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
public List getFuturesData() {
List result = new ArrayList();
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433;User=sa;Password=422322;DatabaseName=test";
//Class.forName ("oracle.jdbc.driver.OracleDriver");
//String url="jdbc:oracle:thin:@192.168.21.113:1521:trade");
conn = DriverManager.getConnection(url);
stmt = conn.createStatement();
String sql = "select contractID,openPrice/1000 openPrice,closePrice/1000 closePrice,marketTime,lastPrice/1000 lastPrice,volumn from ttemp1 order by marketTime";
System.out.println("sql="+sql);
rs = stmt.executeQuery(sql);
int i = 0;
while (rs.next()) {
if (i == 0) {
openPrice = rs.getDouble("lastPrice");
closePrice = rs.getDouble("closePrice");
title = rs.getString("contractID");
}
GraphBean graph = new GraphBean();
graph.setContract(rs.getString("contractID"));
graph.setTime(rs.getString("marketTime"));
graph.setPrice(rs.getDouble("lastPrice"));
graph.setAmount(rs.getInt("volumn"));
result.add(graph);
i++;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
close();
}
return result;
}
public void close() {
try {
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
SimpleDAO dao = new SimpleDAO();
List mylist = dao.getFuturesData();
System.out.println("mylist.size()=" + mylist.size());
System.out.println("openPrice=" + dao.openPrice);
System.out.println("closePrice=" + dao.closePrice);
System.out.println("title=" + dao.title);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -