同样的查询在Oracle SQL Developer中给出正确的结果,而在Java中,它会抛出错误。
SELECT
LOGIN_ID AS GROUPID, FILENAME,
TO_CHAR (CREATEDDATE,'MM/DD/YYYY HH:MI:SS AM') AS CREATDATE,
CASE STATUS
WHEN 2300 THEN 'File downloaded and deleted'
WHEN 2200 THEN 'File Downloaded but not deleted'
WHEN 2100 THEN 'File Created' END STATUS,UMI,PAYLOAD
FROM
CC_CCS_SRD_ADM.TB_MAILBOX_OUTBOUND
WHERE
LOGIN_ID = 'HCLLIN02'
ORDER BY
CREATDATE DESC
java.sql.SQLException:无效列名
在oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3757)
在oracle.jdbc.driver. InsensiveScrollableResultSet.findColumn(InsensiveScrollableResultSet.java:264)
在SQL developer中获取的结果如下:
我尝试在SQL Query Error: Invalid Column Name中提到的查询中运行此查询,结果显示为- Login_ID无效标识符。
我修改的查询是
SELECT *
FROM
(SELECT
LOGIN_ID AS GROUPID, FILENAME,
TO_CHAR (CREATEDDATE, 'MM/DD/YYYY HH:MI:SS AM') AS CREATDATE,
CASE STATUS
WHEN 2300 THEN 'File downloaded and deleted'
WHEN 2200 THEN 'File Downloaded but not deleted'
WHEN 2100 THEN 'File Created'
END STATUS, UMI, PAYLOAD
FROM
CC_CCS_SRD_ADM.TB_MAILBOX_OUTBOUND) DT
WHERE
LOGIN_ID = 'HCLLIN02'
ORDER BY
CREATDATE DESC;
在这个编辑中,添加我的java行:
query = " SELECT LOGIN_ID as GROUPID, \n" +
" FILENAME,TO_CHAR (CREATEDDATE,'MM/DD/YYYY HH:MI:SS AM') AS CREATDATE,\n" +
"\t\t\t\t\tDECODE (STATUS,2300,'File downloaded and deleted',2200,'File Downloaded but not deleted', 2100,'File Created' ) STATUS,UMI,PAYLOAD \n" +
"\t\t\t\t\tFROM CC_CCS_SRD_ADM.TB_MAILBOX_OUTBOUND\n" +
"\t\t\t\t\tWHERE LOGIN_ID = 'HCLLIN02' ORDER BY createddate DESC";
stringBuilder.append(query);
logger.info("after Append Query ");
}
try
{
logger.info("inside try block..");
stmt = con.prepareStatement(stringBuilder.toString());
System.out.println(stringBuilder.toString());
rs = stmt.executeQuery();
while(rs.next())
{
//logger.info("inside select success block.."+ rs.getString(groupId));
TreeMap<String, String> mapToAdd = new TreeMap<String, String>();
mapToAdd.put("GroupID",rs.getString("GROUPID"));
mapToAdd.put("FileName",rs.getString("FILENAME"));
mapToAdd.put("umi", rs.getString("UMI"));
mapToAdd.put("status", rs.getString("STATUS"));
//mapToAdd.put("PAYLOAD", rs.getString("PAYLOAD"));
mapToAdd.put("CreateDate", rs.getString("CREATEDATE"));
1条答案
按热度按时间rjee0c151#
重命名列名。