SQLException {
String w[] = null;
Class.forName(CLASS_NAME);
con = (Connection) DriverManager.getConnection(CONN_NAME, CONN_USER,
CONN_PASSWD);
ptmt = con.prepareStatement("insert into stime(SDATE,STIME) "
+ " values(?,?)");
w = s.split(",");
ptmt.setString(1, w[0]);
ptmt.setString(2, w[1]);
ptmt.executeUpdate();
ptmt.clearParameters();
ptmt.close();
con.close();
}
------------------------------------------------Batch add
public static void Insert(ArrayList
throws ClassNotFoundException, SQLException {
String w[] = null;
Class.forName(CLASS_NAME);
con = (Connection) DriverManager.getConnection(CONN_NAME, CONN_USER,CONN_PASSWD);
ptmt = con.prepareStatement("insert into daily_temp(sdate,type,ym,stime,price) "
+ " values(?,?,?,?,?)");
for (int i = 0; i < s.size(); i++) {
w = s.get(i).split(",");
ptmt.setString(1, w[0].trim());
ptmt.setString(2, w[1].trim());
ptmt.setString(3, w[2].trim());
ptmt.setString(4, w[3].trim());
ptmt.setString(5, w[4].trim());
ptmt.addBatch();
}
ptmt.executeBatch();
ptmt.clearParameters();
con.close();
ptmt.close();
}
沒有留言:
張貼留言