Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

java - ORA-00933 SQL command not properly ended but good in SQL Developer

I am hoping someone can find what is the issue with my query because I am unable to see fault in it and Oracle SQL Developer seems to run the same query as the code in my Java Swing Application just fine.

My query in SQL Developer:

SELECT 
    ad.ID,ad.Script_Name,ad.Current_Status,
    ad.Issues_found_during_run,ad.Testers,
    ad.Run_Date,ad.Tools,u.fTag,u.role,
    dbms_lob.substr(u.avatar) 
FROM 
    allData ad 
INNER JOIN 
    users u 
ON 
    u.fTag = ad.lastUserWhoUpdated 
GROUP BY 
    ad.ID,ad.Script_Name,ad.Current_Status,
    ad.Issues_found_during_run,ad.Testers,
    ad.Run_Date,ad.Tools,u.fTag,u.role,
    dbms_lob.substr(u.avatar) 
ORDER BY 
    ad.ID ASC;

Which run perfectly and returns the needed records I would be expecting it to.

However, that same query in my Java Swing App does not seem to like it as it gives me the error of:

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

My Java Swing App code:

connectToDB();

String query = 
      "SELECT " + 
        "ad.ID," + 
        "ad.Script_Name," + 
        "ad.Current_Status," + 
        "ad.Issues_found_during_run," + 
        "ad.Testers," + 
        "ad.Run_Date," + 
        "ad.Tools," + 
        "u.fTag," + 
        "u.role," + 
        "dbms_lob.substr(u.avatar) " + 
      "FROM " + 
        "allData ad " + 
      "INNER JOIN " + 
        "users u " + 
      "ON " + 
        "u.fTag = ad.lastUserWhoUpdated " +
      "GROUP BY " + 
        "ad.ID," + 
        "ad.Script_Name," + 
        "ad.Current_Status," + 
        "ad.Issues_found_during_run," + 
        "ad.Testers," + 
        "ad.Run_Date," + 
        "ad.Tools," + 
        "u.fTag," + 
        "u.role," + 
        "dbms_lob.substr(u.avatar) " + 
     "ORDER BY " + 
        "ad.ID;";

ResultSet rs = statement.executeQuery(query);            
ResultSetMetaData metaData = rs.getMetaData();
etc..etc..

My structure for those 2 tables is:

SCRIPT_NAME                  VARCHAR2(100 BYTE)
CURRENT_STATUS               VARCHAR2(50 BYTE)
ISSUES_FOUND_DURING_RUN      VARCHAR2(150 BYTE)
TESTERS                      VARCHAR2(30 BYTE)
RUN_DATE                     DATE
TOOLS                        VARCHAR2(20 BYTE)
T_SUITE                      NUMBER(38,0)
NOE2                         VARCHAR2(5 BYTE)
NOE3                         VARCHAR2(5 BYTE)
ID                           NUMBER(38,0)
LASTUSERWHOUPDATED           NUMBER
DATELASTMOD                  DATE

FTAG                         NUMBER(38,0)   
ROLE                         VARCHAR2(15 BYTE)
AVATAR                       CLOB

So, what could I be missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Remove semicolon after the ad.ID like below. You don't need it

"ORDER BY " + 
    "ad.ID";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...