0

I am running below query on the Oracle DB manually and it is working fine and giving the results. The question marks are being replaced with proper values.

DROP TABLE EventTable PURGE  CREATE GLOBAL TEMPORARY TABLE EventTable ( Module NVARCHAR2(512) NULL,EventType NVARCHAR2(512) NULL,ModuleAndEventText NVARCHAR2(512) NULL,Source NVARCHAR2(512) NULL,Severity NVARCHAR2(512) NULL,Node NVARCHAR2(512) NULL,UserSID NVARCHAR2(512) NULL,DesktopId NVARCHAR2(512) NULL,MachineId NVARCHAR2(512) NULL,FolderPath NVARCHAR2(512) NULL,LUNId NVARCHAR2(512) NULL,ThinAppId NVARCHAR2(512) NULL,EndpointId NVARCHAR2(512) NULL,UserDiskPathId NVARCHAR2(512) NULL,GroupId NVARCHAR2(512) NULL,EventID NUMBER NOT NULL,Time TIMESTAMP(6) NULL,Acknowledged NUMBER(38,0)NULL, PRIMARY KEY (EventID))  INSERT INTO EventTable ( Module,EventType,ModuleAndEventText,Source,Severity,Node,UserSID,DesktopId,MachineId,FolderPath,LUNId,ThinAppId,EndpointId,UserDiskPathId,GroupId,EventID,Time,Acknowledged ) SELECT Module,EventType,ModuleAndEventText,Source,Severity,Node,UserSID,DesktopId,MachineId,FolderPath,LUNId,ThinAppId,EndpointId,UserDiskPathId,GroupId,EventID,Time,Acknowledged FROM sdevent WHERE (UPPER(UserSID) = ?) AND (Time BETWEEN ? AND ?) AND ((UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?)) SELECT COUNT(*)  FROM EventTable E  LEFT OUTER JOIN ((SELECT* FROM ( SELECT sdevent_data.eventid, name, strValue FROM sdevent_data INNER JOIN EventTable ET ON sdevent_data.eventid=ET.eventid) SourceTable PIVOT (MAX(strValue) FOR name IN ('ApplicationId','MachineId','RDSServerId','FarmId','SessionId','UserDisplayName','DesktopDisplayName','ApplicationDisplayName','MachineName','FarmDisplayName','EndUserDisplayName','ThinAppDisplayName','ProcessName','RemoteApplicationId','RemoteApplicationDescription')) PivotTable)) strValueTable ON E.eventid=strValueTable.eventid LEFT OUTER JOIN (SELECT EventID,intValue FROM sdevent_data WHERE (Name = 'ProcessId')) ProcessId ON E.EventID = ProcessId.EventID LEFT OUTER JOIN (SELECT EventID,strBlobValue FROM sdevent_data WHERE (Name = 'TimingProfilerTree')) TimingProfilerTree ON E.EventID = TimingProfilerTree.EventID WHERE (UPPER(UserSID) = ?) AND (Time BETWEEN ? AND ?) AND ((UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?) OR (UPPER(EventType) = ?))

But when I am running the same query from Java JDBC, it is giving me an SQL Exception --

 java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended

    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
    at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257)
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:225)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:53)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:943)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1150)

Below is the snippet of the java code which is creating the above query--

StringBuilder countQuery = new StringBuilder();

       countQuery.append(" DROP TABLE EventTable PURGE ");
       countQuery.append(" CREATE GLOBAL TEMPORARY TABLE EventTable ( ");
       countQuery.append(getTempTableAttributes());
       countQuery.append(" INSERT INTO EventTable ( ");
       countQuery.append(getEventTableAttributes());
       countQuery.append(" ) SELECT ");
       countQuery.append(getEventTableAttributes());
       countQuery.append(" FROM ");
       countQuery.append(this.eventTableName);
       if (def.filter != null) {
           countQuery.append(" WHERE ");
           countQuery.append(applyFilterToQuery(def.filter));
       }
       countQuery.append(" SELECT COUNT(*) ");
       countQuery.append(" FROM ");
       countQuery.append("EventTable E ");
       countQuery.append(getLeftJoinClause());
       if (def.filter != null) {
           countQuery.append(" WHERE ");
           countQuery.append(applyFilterToQuery(def.filter));
       }
       String query = countQuery.toString();

When I print the string query it prints the above query which works fine. So not sure what is going wrong when I run from Java. Is there any way to see the actual query that runs in the Oracle DB similar to MS SQL profiler?

1
  • 1
    The query string you show contains THREE SQL statements: DROP TABLE, CREATE TABLE and INSERT. They need to be run in separate calls. Commented May 3, 2019 at 4:15

1 Answer 1

1

if the query is running fine, I suspect there might be some problem with query parameters. Put up debug point when the query executes, and check the replaced parameters.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok will do that, do you suspect something in the java code given above that might cause the problem. Also I am using Oracle 18c, can you tell me how to enable profiler so that I can see the exact query which hits the database

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.