Paulo Roberto
Paulo Roberto

Reputation: 1548

Select the Oracle java - ORA-00905: not found keyword

I'm trying to run a connection test in the bank and extract some information , apena s to study it, but I'm bumping into the following error:

    Exception in thread "main" java.sql.SQLException: ORA-00905: 
not found keyword

        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
        at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
        at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:207)
        at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:790)
        at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
        at oracle.jdbc.driver.T4CStatement.executeMaybeDescribe(T4CStatement.java:830)
        at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1132)
        at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1272)
        at Principal.Principal.main(Principal.java:46)

when I run the code with a simple select , such as select * from plan; it works perfectly.

How can I fix this error code and there is a simpler way to perform a select in oracle database or this code is enough?

I want to run the query shows all the column values ​​1 ( ICCID ) , on the island.

ORA-00905: palavra-chave não encontrada

package Principal;
import java.sql.*;


public class Principal {

         public static void main(String[] args) throws Exception {

                   Connection conexao = ObterConexao();

                   Statement statement = conexao.createStatement();


                   String query = "SELECT a.rp_package_value AS ICCID, "
                           + "c.rrs_resource_value AS IMSI, "
                           + "  ( "
                                + "  CASE "
                                   + " WHEN (SUBSTR (c.rrs_resource_value, 6, 1) = SUBSTR (a.rp_package_value, 9, 1)) "
                                    + "AND (SUBSTR (c.rrs_resource_value, 6, 2) <> '00') -- valida se o HLR existe "
                                    + "THEN 'Valid' "
                                    + "ELSE 'Invalid' "
                                  + "END ) AS IMSI_CHECK , "
                                  + "rrs_resource_sts Status, rp_package_sts "
                                + "FROM mtaapp20.rm_packages a, "
                                  + "mtaapp20.rm_package_content b, "
                                  + "mtaapp20.rm_resource_stock c "
                                + "WHERE a.rp_package_value IN "
                                  + "(SELECT RRS_RESOURCE_VALUE "
                                  + "FROM mtaapp20.rm_resource_stock c "
                                  + "WHERE c.rrs_resource_tp_id = 6 "
                                  + "AND c.rrs_resource_pool = 30 "
                                  + "--AND a.rp_package_value like '89955053110002178148' "
                                  + "AND SUBSTR (RRS_RESOURCE_VALUE, 9, 2) like '%1%'  "
                                  + "AND c.rrs_resource_sts = 'ASSIGNED' "
                                  + ") "
                                + "AND a.rp_package_id = b.rpc_package_id "
                                + "AND c.rrs_resource_sts = a.rp_package_sts "
                                + "AND b.rpc_component_tp_id = 5 "
                                + "AND b.rpc_component_vl_id = c.rrs_id "
                                + "ORDER BY a.sys_creation_date DESC " ;





                   ResultSet resultSet = statement.executeQuery(query);


                   if (resultSet.next()) {

                            System.out.println(resultSet.getObject(2));

                   }

         }


         private static Connection ObterConexao() {

                   Connection conexao = null;


                   try {

                            Class.forName("oracle.jdbc.driver.OracleDriver");

                            conexao = DriverManager.getConnection(

                                               "jdbc:oracle:thin:@BRUX:1521:T00WM11", "user", "password");

                   } catch (ClassNotFoundException e) {

                            e.printStackTrace();

                   } catch (SQLException e) {

                            e.printStackTrace();

                   }


                   return conexao;

         }

}

Upvotes: 1

Views: 1269

Answers (2)

Volodymyr Pasechnyk
Volodymyr Pasechnyk

Reputation: 111

You have an SQL comment in this line:

+ "AND (SUBSTR (c.rrs_resource_value, 6, 2) <> '00') -- valida se o HLR existe "

The problem is that Java code doesn't know about any newlines in your SQL code, and thus ignore everything after "--". Just change this line to:

+ "AND (SUBSTR (c.rrs_resource_value, 6, 2) <> '00') "

Upvotes: 6

MT0
MT0

Reputation: 168671

As Volodymyr Pasechnyk noted the issue is with the comments in the SQL query.

You can either remove the comments from the query or change them from -- to wrapping the commented code in /* and */.

So change:

+ "AND (SUBSTR (c.rrs_resource_value, 6, 2) <> '00') -- valida se o HLR existe "

to

+ "AND (SUBSTR (c.rrs_resource_value, 6, 2) <> '00') /* valida se o HLR existe */ "

and change:

+ "--AND a.rp_package_value like '89955053110002178148' "

to

+ "/*AND a.rp_package_value like '89955053110002178148'*/ "

Upvotes: 2

Related Questions