2017-07-28 61 views
0


我想用在春季查詢, 一個表名,但是當我執行它,我得到這個以下錯誤:
春@Query刪除報價

"could not extract ResultSet; SQL [n/a]; nested exception is 
org.hibernate.exception.SQLGrammarException: could not extract ResultSet" 


由於彈簧自動添加引號「的時候參數是一個字符串PARAM ..

@Query(value = "desc :name", nativeQuery = true) 
List<RepositoryColumn> getColumnFromRepository(@Param("name") String name); 

在其他情況下,我想"desc table_name"而不是"desc 'table_Name'"

任何想法?

+1

這與Spring沒有任何關係,但參數替換如何與JDBC一起工作。這些查詢不能使用參數綁定。 –

+0

您可以創建一個程序,該程序將「執行即時」這個查詢 –

回答

0
SELECT * 
FROM information_schema.columns 
WHERE 
    table_name = :name 

嘗試相同的方式。而不是*你可以選擇必要的列

+0

謝謝!它的工作,但現在我怎麼能得到一個'Select * FROM table_name'的等價物 – Fanor79

+0

這是不可能的。不支持使用表名作爲參數。 – StanislavL

+0

arf ..謝謝.. – Fanor79