我试图获取一个查询的值并将值放在下一个查询的条件中。问题是从数据类型' CHAR'的隐式转换获得异常。到' INT'不允许'。
代码是:
import com.sybase.jdbcx.*;
public class Provider_Rate {
public static void main(String[] args) throws SQLException {
providerRate();
}
// String dbuserName = "faoper"; //TestData.getData("Application_Data",
// "Username");
// String dbpassword = "test69"; //TestData.getData("Application_Data",
// "Password");
// String Query = "SELECT * FROM facets_cps_01..CPS_PROV_RATE WHERE NWPR_PFX
// = 'CD01'and PRPR_ID <> ''"; //TestData.getData("Application_Data",
// "Query");
public static void providerRate() throws SQLException {
String host = "CPSRLSE";
String url = "jdbc:sybase:Tds:" + host + ":12028";
String username = "";
String password = "";
SybDriver sybDriver = null;
Connection conn = null;
String query1 = "facets_cps_01..CPS_PROV_RATE WHERE NWPR_PFX = 'CD01'and PRPR_ID <> ''";
String query21 = "SELECT DISTINCT DPRS.DPRS_RATE FROM facets_rlse_01..CMC_DPRS_PRICE DPRS JOIN facets_rlse_01..CMC_DPPC_PRICE DPPC ON DPRS.SEIP_PFX = DPPC.DPPC_RCS_PFX AND DPRS.ZPCD_AREA = DPPC.DPPC_RCS_AREA JOIN facets_rlse_01..CMC_DPDF_DP_DEFN DPDF ON DPPC.DPPC_PRICE_ID = DPDF.DPPC_PRICE_ID JOIN facets_rlse_01..CMC_AGAG_AGREEMENT AGAG ON DPDF.PDBC_PFX = AGAG.AGDP_PFX JOIN facets_cps_01..CPS_PROV_RATE PROV ON AGAG.AGAG_ID = PROV.AGAG_ID WHERE PROV.PROCEDURE_CD BETWEEN DPDF.DPDF_DP_ID_LOW AND DPDF.DPDF_DP_ID_HIGH AND DPRS.DPDP_ID = PROV.PROCEDURE_CD AND PROV.PROCEDURE_CD = "; // '00120'";
String query22 = "AND DPRS.DPRS_TERM_DT > GETDATE() AND PROV.PRPR_ID = "; // '0004216'";
List<String> PRID = new ArrayList();
List<String> PCD = new ArrayList();
try {
// FileWriter fw = new FileWriter(filename);
sybDriver = (SybDriver) Class.forName("com.sybase.jdbc3.jdbc.SybDriver").newInstance();
System.out.println("Driver Loaded");
conn = DriverManager.getConnection(url, "faoper", "test69");
Statement stmt1 = conn.createStatement();
ResultSet rs = stmt1.executeQuery("SELECT * FROM " + query1);
while (rs.next()) {
PRID.add(rs.getString("PRPR_ID"));
PCD.add(rs.getString("PROCEDURE_CD"));
}
/*
* while(it1.hasNext() && it2.hasNext()) { System.out.println(); }
*/
stmt1.close();
Statement stmt2 = conn.createStatement();
for (int i = 0; i < PRID.size(); i++) {
// ResultSet rs2 = stmt2.executeQuery(query21 + PCD.get(i) +
// query22 + PRID.get(i));
String tmp = "SELECT DISTINCT DPRS.DPRS_RATE FROM facets_rlse_01..CMC_DPRS_PRICE DPRS JOIN facets_rlse_01..CMC_DPPC_PRICE DPPC ON DPRS.SEIP_PFX = DPPC.DPPC_RCS_PFX AND DPRS.ZPCD_AREA = DPPC.DPPC_RCS_AREA JOIN facets_rlse_01..CMC_DPDF_DP_DEFN DPDF ON DPPC.DPPC_PRICE_ID = DPDF.DPPC_PRICE_ID JOIN facets_rlse_01..CMC_AGAG_AGREEMENT AGAG ON DPDF.PDBC_PFX = AGAG.AGDP_PFX JOIN facets_cps_01..CPS_PROV_RATE PROV ON AGAG.AGAG_ID = PROV.AGAG_ID WHERE PROV.PROCEDURE_CD BETWEEN DPDF.DPDF_DP_ID_LOW AND DPDF.DPDF_DP_ID_HIGH AND DPRS.DPDP_ID = PROV.PROCEDURE_CD AND PROV.PROCEDURE_CD ="
+ **PCD.get(i)** + "AND DPRS.DPRS_TERM_DT > GETDATE() AND PROV.PRPR_ID =" + **PRID.get(i)**;
ResultSet rs2 = stmt2.executeQuery(tmp);
while (rs2.next()) {
System.out.println(rs2.getString(1));
}
}
} catch (InstantiationException ex) {
System.out.println("Exception");
ex.printStackTrace();
} catch (IllegalAccessException ex) {
System.out.println("Exception");
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
System.out.println("Exception");
ex.printStackTrace();
} catch (SQLException ex) {
System.out.println("Exception");
ex.printStackTrace();
} finally {
conn.close();
}
}
}
如何实现这一目标?
从第一个查询中我获取列PRPR_ID
和PROCEDURE_CD
的值并存储到字符串列表中。
第二个查询的条件有这两个值。但这不起作用。 显示以下错误:
来自数据类型&#39; CHAR&#39;的隐式转换到&#39; INT&#39;是不允许的。