青纱帐下魂 2021-06-04 10:22 采纳率: 42.9%
浏览 428
已采纳

SQLSyntaxErrorException: ORA-00900: 无效 SQL 语句

List<String> listsql=new ArrayList<>();

listsql.add("select round((1-busy.value/tol.value)*100,2) from (select sum(count) value from v$waitstat where class in ('data block','segment header','undo header','undo block'))busy, (select value from v$sysstat where name='session logical reads')tol");

listsql.add("select round((1-(physical.value-direct.value-lobs.value)/logical.value)*100,2) from v$sysstat physical,v$sysstat direct,v$sysstat lobs,v$sysstat logical where physical.NAME='physical reads' and direct.name='physical reads direct' and lobs.name='physical reads direct (lob)' and logical.NAME='session logical reads'");

listsql.add("select round(sum(pins-reloads)/sum(pins)*100,2) from v$librarycache");

listsql.add("select round((1-hard.value/total.value)*100,2) from v$sysstat hard,v$sysstat total where hard.NAME='parse count (hard)' and total.NAME='parse count (total)'");

listsql.add("select round((1-cpu.value/total.value)*100,2) from v$sysstat cpu,v$sysstat total where cpu.NAME='parse time cpu' and total.NAME='parse time elapsed'");

listsql.add("select round((1-waits.value/redos.value)*100,2) from v$sysstat waits,v$sysstat redos where waits.NAME='redo log space requests' and redos.NAME='redo entries'");

listsql.add("select round((1-disk.value/(disk.value+memory.value))*100,2) from v$sysstat disk,v$sysstat memory where disk.NAME='sorts (disk)' and memory.NAME='sorts (memory)'");

listsql.add("select round((1 - (a.value/b.value))*100,2) from v$sysstat a,v$sysstat b where a.name='parse count (hard)' and b.name='parse count (total)'");

listsql.add("select round((1-sum(misses+immediate_misses)/sum(gets+immediate_gets))*100,2) from v$latch");

listsql.add("select round((1-parse.value/total.value)*100,2) from v$sysstat parse,v$sysstat total where parse.NAME='parse time cpu' and total.NAME='CPU used by this session'");

List<DB_jiemi> list1=HttpClientHelper.send();

List<DB_jiemi> list=new ArrayList<DB_jiemi>();
for (int i = 0; i < list1.size(); i++) {
   if(ip.equals(list1.get(i).getIP()))
      list.add(list1.get(i));
}
Map map = new HashMap<>();
String url="jdbc:oracle:thin:@"+list.get(0).getIP()+":"+list.get(0).getPORT()+":"+list.get(0).getDB_SERVERNAME();
String user=list.get(0).getDB_USER_S();
String password=list.get(0).getDB_PWD_S();
String drive="oracle.jdbc.driver.OracleDriver";
Connection con = dbUtil.getConnection(url,user,password,drive);
for (int i = 0; i < listsql.size(); i++) {
   PreparedStatement pst = con.prepareStatement(String.valueOf(listsql.size()));
   ResultSet rs = pst.executeQuery();
   while(rs.next()) {
      map.put("DBcheck",rs);
   }
   //dbUtil.close(con,pst,rs);
   rs.close();
   pst.close();
}
con.close();
return map;

我要在for循环里一次执行一条sql语句在将查询的结果放入到map中返回给前端,但是现在报java.sql.SQLSyntaxErrorException: ORA-00900: 无效 SQL 语句,sql语句单独执行是没有问题的,代码中加粗的位置,查询和放入map中的方式我有点不清楚是否正确!

 

 

  • 写回答

1条回答 默认 最新

  • 芫尘梦 2021-06-04 10:42
    关注
    PreparedStatement pst = con.prepareStatement(String.valueOf(listsql.size())); 改成
    PreparedStatement pst = con.prepareStatement(listsql.get(i));
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。
  • ¥15 已知隐函数其中一个变量τ的具体值,求另一个变量
  • ¥15 r语言Hurst指数
  • ¥15 RT-Thread Studio编译问题