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

当我排除第二个查询时,一切正常。同样,当我用“ 21901123456456”(即s变量的值)替换“ + 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);
    }
    }
}

最佳答案

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


AND前的空格
s是一个字符串,因此您必须在选择中将其传递给字符串,因此请添加'
为避免这种情况,您应该使用准备好的语句!


"SELECT PARAMETERVALUE FROM
    TERTIOTEST.SERVICEPARAMETER WHERE SUBSCRIBERKEY = '"+s+"' AND servicename =
    'TARIFF' AND PARAMETERNAME = 'tariff'"


您应该检查两个选择语句

关于java - java.sql.SQLSyntaxErrorException:ORA-01722:无效的number_where输入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56580446/

10-09 23:23