NetBeans上のmysqlサーバーに支えられたGlassfishサーバー上に簡単な小さなWebサービスを作成しようとしています。
非常にシンプルな通貨換算サービスとして設計されています
これがその予定です
INTとしての金額(常にGBp)と、文字列として変換するための通貨が必要です。
次に、サービスはデータベーステーブルからその通貨を検索し、次のようなクエリでコンバージョン率を取得します。
select * from exchange.rates where currency = string
次に、簡単な計算を実行してお金を通貨に変換し、金額を返します
問題は、mysqlサーバーからその変換率を呼び出す方法がわからないことです。試してみましたが、何も起こらず、入力したのと同じ量を取得し続けます。
ユーロを入力してみましたが、データベースでそのレートを設定しましたが、Webサービスをテストしたときに10が戻ってきました。
/**
* Web service operation
*/
@WebMethod(operationName = "convert")
public int convert(@WebParam(name = "currency") String currency, @WebParam(name = "amount") int amount) {
int newamount = 0;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/exhange",
"root", "25587");
PreparedStatement st =
con.prepareStatement("select * from rates where currency = '" + currency+"'");
ResultSet rs = null;
rs = st.executeQuery();
rs.first();
newamount =rs.getInt("conversion") * amount;
return newamount;
} catch (Exception e) {
System.out.println("error");
}
return amount;
}