java.sql.SQLSyntaxErrorException: ORA-00900: 无效 SQL 语句

青纱帐下魂 2021-06-04 10:12:22
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 语句
应该怎么解决?

放入到map的方式也应该是有错的!

...全文
1692 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
冰思雨 2021-06-07
  • 打赏
  • 举报
回复
PreparedStatement pst = con.prepareStatement(String.valueOf(listsql.size()));

这个语句有问题。

PreparedStatement pst = con.prepareStatement(listsql.get(i)));

使用 SQL 语句来生成PreparedStatement对象才行。

 

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧