简体   繁体   English

java.sql.SQLSyntaxErrorException:ORA-01722:number_where IN无效

[英]java.sql.SQLSyntaxErrorException: ORA-01722: invalid number_where IN

I'm trying to execute the code below. 我正在尝试执行下面的代码。 First sql query gave me some needed 'IMSI' number which I store in 's' variable and than I used it to select second and third select query. 第一个SQL查询给了我一些所需的'IMSI'号码,我存储在's'变量中,而不是用它来选择第二个和第三个选择查询。

When I exclude second query everything went OK. 当我排除第二个查询时,一切正常。 Also when I replace "+s+" with '21901123456456' which is value of s variable, code finish successfully. 此外,当我将'+ s +'替换为'21901123456456'(s变量的值)时,代码成功完成。 But when I execute code as below I got error from subject. 但是当我执行下面的代码时,我得到了来自主题的错误。

import java.sql.*;
import java.util.Scanner;
class stanjeBroja{  
public static void main(String args[]){  
    Scanner reader = new Scanner(System.in);
    System.out.println("Unesi MSISDN");
    // get user input for min range
    String min=reader.nextLine();
    String s = "";
    try{    
        //step1 load the driver class  
        Class.forName("oracle.jdbc.driver.OracleDriver");  
        //step2 create  the connection object  
        Connection con=DriverManager.getConnection(  
        "jdbc:oracle:thin:@ip:port:sid","user","pass");  
        //step3 create the statement object  
        Statement stmt=con.createStatement();  
        //step4 execute query  
        ResultSet rs=stmt.executeQuery("SELECT 
SUBSCRIBERKEY,ALTERNATESUBSCRIBERKEY FROM 
TERTIOTEST.ALTERNATESUBSCRIBERKEY 
WHERE ALTERNATESUBSCRIBERKEY ="+min+"");  
        while(rs.next()){  
            System.out.println("IMSI: "+rs.getString(1)+"  MSISDN: 
"+rs.getString(2)+"  ");  
            s = rs.getString(1);
        }
        ResultSet rs1=stmt.executeQuery("SELECT servicename FROM 
TERTIOTEST.SUBSCRIBERSERVICE WHERE SUBSCRIBERKEY = "+s+"AND servicename 
IN 
('STD','VPNNUM','HLR','VPNUNR','STDHYB','VOXX','VPNFA')");  
        while(rs1.next()){  
            System.out.println("SERVISI: "+rs1.getString(1)+"  ");  
        }
        ResultSet rs2=stmt.executeQuery("SELECT PARAMETERVALUE FROM 
TERTIOTEST.SERVICEPARAMETER WHERE SUBSCRIBERKEY = "+s+"AND servicename = 
'TARIFF' AND PARAMETERNAME = 'tariff'");  
        while(rs2.next()){  
            System.out.println("TARIFA: "+rs2.getString(1)+"  ");  
        }
        //step5 close the connection object  
        con.close();   
    }
    catch(Exception e){
        System.out.println(e);
    }   
    }  
}  

you select string needs some improvements 你选择字符串需要一些改进

  • space before AND 空间之前AND
  • s is a string so you have to pass it a string in your select so add ' around. s是一个字符串,所以你必须在你的选择中传递一个字符串,所以添加' around。 to avoid that, you should use prepared Statement! 为避免这种情况,您应该使用准备好的声明!
"SELECT PARAMETERVALUE FROM 
    TERTIOTEST.SERVICEPARAMETER WHERE SUBSCRIBERKEY = '"+s+"' AND servicename = 
    'TARIFF' AND PARAMETERNAME = 'tariff'"

you should check both of your select statements 你应该检查你的两个选择陈述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误 --> java.sql.SQLSyntaxErrorException: ORA-01722: 无效号码 - ERROR --> java.sql.SQLSyntaxErrorException: ORA-01722: invalid number java.sql.SQLSyntaxErrorException: ORA-01722 - java.sql.SQLSyntaxErrorException: ORA-01722 问题休眠(java.sql.SQLSyntaxErrorException:ORA-01722:无效的数字) - Issue hibernate (java.sql.SQLSyntaxErrorException: ORA-01722: invalid number) java.sql.SQLSyntaxErrorException:ORA-01722:refcursor上的resultSet.next()时数字无效,我不明白为什么? - java.sql.SQLSyntaxErrorException: ORA-01722: invalid number while resultSet.next() on refcursor and I don't understand why? java.sql.SQLSyntaxErrorException-ORA-01722: 无效数字 - 准备好的语句 - java.sql.SQLSyntaxErrorException-ORA-01722: invalid number - Prepared statement java.sql.SQLSyntaxErrorException:ORA-00922:缺少或无效的选项 - java.sql.SQLSyntaxErrorException: ORA-00922: missing or invalid option java.sql.SQLSyntaxErrorException:ORA-00911:无效字符 - java.sql.SQLSyntaxErrorException: ORA-00911: invalid character java.sql.SQLSyntaxErrorException:ORA-00903:表名无效 - java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name java.sql.SQLSyntaxErrorException:ORA-00904:“columnName”:无效标识符 - java.sql.SQLSyntaxErrorException: ORA-00904: “columnName”: invalid identifier java.sql.SQLSyntaxErrorException:ORA-00904::无效的标识符 - java.sql.SQLSyntaxErrorException: ORA-00904: : invalid identifier
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM