JDBC 的 传值问题
|
gabriel
堕落的恶魔
铜牌会员
|
1 # 大 中 小 发表于 2008-05-16 14:05:38
搞定select * From ops$e21team4_ro.RPT_WFX_MONTHLY
select to_char(TRUNC(SERV_STRT_DATE,'MM'),'yyyymm') AS MONTH, COUNT(DISTINCT LINE_NO) AS LINE_NO From lis_line_subscription where prod_id = 789 and sts<>'I' GROUP BY TRUNC(SERV_STRT_DATE,'MM')
我需要把 第2个SQL查询出的数据根据 相对应的 MONTH 插入到第一个 表ops$e21team4_ro.RPT_WFX_MONTHLY 里的LINE_CNT字段中 package test;
import java.io.Serializable;
import java.sql.*;
import java.util.ArrayList;
import java.sql.Date;
import java.text.SimpleDateFormat;
public class JavaExcel implements Serializable{
static Connection conn = null;
static PreparedStatement pstmt = null;
public static void main(String[] args) throws SQLException{
getConnection();
conn.setAutoCommit(false);
updateLineNo();
conn.commit();
conn.setAutoCommit(true);
conn.close();
}
public static void updateLineNo() throws SQLException{
ArrayList al = getLineNo();
try {
for (int j = 0; j < al.size(); j++) {
String sql = "update ops$e21team4_ro.RPT_WFX_MONTHLY "
+ "set LINE_CNT=? "
+ "where MON=?";
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, ((JeDO) al.get(j)).getLineNo());
pstmt.setString(2, ((JeDO)al.get(j)).getMonth());
System.out.println(sql);
System.out.println(((JeDO)al.get(j)).getMonth()+"|");
System.out.println(((JeDO)al.get(j)).getLineNo()+"|");
int cnt= pstmt.executeUpdate();
System.out.println("rows updated:"+cnt);
pstmt.close();
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
System.out.println(e.getMessage());
}
}
/*public static ArrayList getMon() throws SQLException{
String sql = "select mon from ops$e21team4_ro.RPT_WFX_MONTHLY";
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
ArrayList jdo = new ArrayList();
while(rs.next()){
jdo.add(rs.getString(1));
}
for(int i=0;i<jdo.size();i++){
System.out.println("------------"+jdo.get(i));
String sql1 = "";
}
pstmt.close();
return jdo;
}*/
public static ArrayList getLineNo() throws SQLException{
ArrayList result = new ArrayList();
String sql = "select to_char(TRUNC(SERV_STRT_DATE,'MM'),'yyyymm') AS MONTH, " +
"COUNT(DISTINCT LINE_NO) AS LINE_NO " +
"From lis_line_subscription where prod_id = 789 and sts<>'I' " +
"GROUP BY TRUNC(SERV_STRT_DATE,'MM') ";
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
JeDO bean = new JeDO();
bean.setMonth(rs.getString(1));
bean.setLineNo(rs.getInt(2));
result.add(bean);
}
for(int i=0;i<result.size();i++){
System.out.println(">>>>>>>>>>>>"+((JeDO) result.get(i)).getLineNo());
System.out.println("<<<<<<<<<<<<"+((JeDO) result.get(i)).getMonth());
}
pstmt.close();
return result;
}
public static void getConnection(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(java.lang.ClassNotFoundException e){
System.out.println(e.getMessage());
}
try {
String url = "jdbc:oracle:thin:@neptune:1523:E21DB2";
String user = "ops$e21team4_ro";
String password = "abcapr";
try {
conn = DriverManager.getConnection(url, user, password);
} catch (Exception e) {
System.out.println(e.getMessage());
}
} catch (Exception e) {
// TODO: handle exception
System.out.println(e.getMessage());
}
}
}
class JeDO implements Serializable{
int lineNo;
String month;
public int getLineNo() {
return lineNo;
}
public void setLineNo(int lineNo) {
this.lineNo = lineNo;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
}
----------------------http://michelecindy.javaeye.com
|
|||||
|



