1

SQLパーサーをJavaに使用できる優れた実装例または使用シナリオを誰かが提案できますか.

特定のパラメーター、並べ替え基準などに基づいて、UI に表示されるデータをフィルター処理する必要があるアプリケーションがあります。これに関していくつか疑問があります。

1)これはこれに対する理想的な解決策になりますか?

2) UI は Java レイヤーにクエリを提供する役割をどのように果たすことができますか?

4

2 に答える 2

1

Java アプリで SQL クエリを動的に構築し、この SQL を使用してデータをフェッチしますか? 次のようなSQLがあるとします。

select salary from emp where dept='sales'

ユーザーがUIから年齢> 40などの他のフィルターを選択すると、SQLは次のようになります。

select salary from emp where dept='sales' and age > 40

もちろん、より複雑なフィルターを追加したり、並べ替え句を追加したりすることもできます。

これを実現するには、完全なSQL パーサーが役立ちます。Java SQL パーサーに基づいてSQL ステートメントを分解、変更、再構築する方法を示すデモを次に示します。

于 2012-01-19T02:22:15.670 に答える
0

I don't know what a SQL parser is supposed to be. Applications don't have to parse SQL. Thay have to execute SQL queries, and thus potentially generate SQL queries dynamically. But it's the database that parses the SQL, not the application.

The UI doesn't typically provide a query to the service layer. The UI doesn't have to know how the data is persisted and which queries to execute. It's not its responsibility. The UI should just pass Filter or Criteria objects to the service layer, which transforms the filter or criteria into a SQL query, executes the query, transforms the results into Java objects, and return those objects to the UI, which displays these objects.

于 2012-01-18T10:13:31.607 に答える