2017-09-15 107 views
1

下面是我的JDBC查询:JDBC SQL命令无法正常结束

Connection con = DB_Connection.get_dbConnectionSingleTime("TESTA2", "ao3652", "reset123", "Oracle"); 
    String premium = "Premiums"; 
    String query = "SELECT * FROM ELP_COUNTRY,ELP_COUNTRY_Tax where"+ 
"ELP_COUNTRY.COUNTRY_ID=Elp_Country_Tax.Country_Id"+ 
"and ELP_COUNTRY.DESCRIPTION=? and GETENGLISHDESCFROMLISTITEM(ELP_COUNTRY_TAX.TAX_TYPE_ID)=?"+ 
"and ELP_COUNTRY_TAX.DEALER_ID is null order by ELP_COUNTRY_TAX.Effective_Date DESC"; 
    //-----------------------------------------------------------------------------^ 
    try(PreparedStatement pst = con.prepareStatement(query)){ 
     pst.setString(1, Country);// Set the input 
     pst.setString(2, premium); 
     ResultSet rs = pst.executeQuery(); 
     rs = pst.getResultSet(); 
     while(rs.next()) 
     { 
      System.out.println(rs.next()); 
     } 
    } 

上面的代码是通过JDBC被抛出SQL命令无法正常结束。

及以下这是我工作的SQL查询精细

SELECT *FROM ELP_COUNTRY,ELP_COUNTRY_Tax where 
ELP_COUNTRY.COUNTRY_ID=Elp_Country_Tax.Country_Id 
and ELP_COUNTRY.DESCRIPTION='Brasil' and GETENGLISHDESCFROMLISTITEM(ELP_COUNTRY_TAX.TAX_TYPE_ID)='Premiums' 
and ELP_COUNTRY_TAX.DEALER_ID is null order by ELP_COUNTRY_TAX.Effective_Date DESC 

所以任何一个可以建议我一些我需要在JDBC查询做了修正?

"SELECT * FROM ELP_COUNTRY,ELP_COUNTRY_Tax where"+ 
"ELP_COUNTRY.COUNTRY_ID=Elp_Country_Tax.Country_Id"+ 
"and ELP_COUNTRY.DESCRIPTION=? and GETENGLISHDESCFROMLISTITEM(ELP_COUNTRY_TAX.TAX_TYPE_ID)=?"+ 
"and ELP_COUNTRY_TAX.DEALER_ID is null order by ELP_COUNTRY_TAX.Effective_Date DESC" 

例如此:

回答

1

在每个字符串的末尾追加空间

" ....... where"+ 
"ELP_COUNTRY ......." 

给出了这样的字符串:

" ...... whereELP_COUNTRY....." 

和此:

....... X_TYPE_ID)=?"+ 
"and ELP_COU .......... 

结果:

....... X_TYPE_ID)=?and ELP_COU .......... 

如果where后插入空格:

" ....... where "+ 
"ELP_COUNTRY ......." 

你会得到正确的SQL语句:

" ...... where ELP_COUNTRY....." 
相关问题