2017-09-15 101 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....." 
相關問題