小编See*_*rUK的帖子

不能在JDBC PreparedStatement中使用LIKE查询?

查询代码和查询:

ps = conn.prepareStatement("select instance_id, ? from eam_measurement where resource_id in (select RESOURCE_ID from eam_res_grp_res_map where resource_group_id = ?) and DSN like '?' order by 2");
ps.setString(1,"SUBSTR(DSN,27,16)");
ps.setInt(2,defaultWasGroup);
ps.setString(3,"%Module=jvmRuntimeModule:freeMemory%");
rs = ps.executeQuery();
while (rs.next()) { bla blah blah blah ...
Run Code Online (Sandbox Code Playgroud)

返回一个空的ResultSet.

通过基本的调试我发现它的第三个绑定是问题,即

DSN like '?'
Run Code Online (Sandbox Code Playgroud)

我尝试了各种各样的变化,其中最明智的似乎是使用:

DSN like concat('%',?,'%')
Run Code Online (Sandbox Code Playgroud)

但这不起作用,因为我错过'了连接字符串的两边,所以我尝试:

DSN like ' concat('%',Module=P_STAG_JDBC01:poolSize,'%') ' order by 2
Run Code Online (Sandbox Code Playgroud)

但我似乎无法找到一种方法让他们参与其中.

我错过了什么?

java oracle jdbc sql-like

30
推荐指数
3
解决办法
6万
查看次数

使用Java中的循环创建变量名称?

第一次海报,长时间读者所以对我温柔:)

请参阅以下代码,该代码用于生成财务年度中每月开始和结束的时间戳.

int year = 2010;
// Financial year runs from Sept-Aug so earlyMonths are those where year = FY-1 and lateMonths are those where year = FY
int[] earlyMonths = {8, 9, 10, 11}; // Sept to Dec
int earlyYear = year -1;
for (int i : earlyMonths) {
    month = i;
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(earlyYear,month,1,0,0,0);
    Long start = cal.getTimeInMillis();
    cal.clear();
    cal.set(earlyYear,month,1);
    lastDayofMonth = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
    cal.set(earlyYear,month,lastDayofMonth,23,59,59);
    Long end = cal.getTimeInMillis();
}
int[] lateMonths = {0, 1, 2, …
Run Code Online (Sandbox Code Playgroud)

java variables loops dynamic names

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×2

dynamic ×1

jdbc ×1

loops ×1

names ×1

oracle ×1

sql-like ×1

variables ×1