java.sql.SQLSyntaxErrorException:ORA-01722:无效的number_where输入

时间:2019-06-13 12:24:39

标签: java sql oracle

我正在尝试执行以下代码。第一个sql查询给了我一些需要的'IMSI'编号,该编号存储在's'变量中,然后我用它来选择第二个和第三个select查询。

当我排除第二个查询时,一切正常。同样,当我将“ + s +”替换为“ 21901123456456”(它是s变量的值)时,代码也会成功完成。  但是当我如下执行代码时,我收到了主题错误。

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);
    }   
    }  
}  

1 个答案:

答案 0 :(得分:0)

您选择的字符串需要一些改进

  • AND之前的空格
  • s是一个字符串,因此您必须在选择的字符串中传递它,因此请添加'。 为避免这种情况,您应该使用准备好的语句!
"SELECT PARAMETERVALUE FROM 
    TERTIOTEST.SERVICEPARAMETER WHERE SUBSCRIBERKEY = '"+s+"' AND servicename = 
    'TARIFF' AND PARAMETERNAME = 'tariff'"

您应该检查两个选择语句