私はデータベースorder
とprice
とdeposit
フィールドをfloat型に設定しています。私はまた、注文を検索するためにjava GUIを実装しています、問題は、データベースで注文を検索しようとしたときです。何も見つかりません。なぜなら、文字列を浮動小数点に変換し、 55.問題は何ですか? 私は双方の側、Java側とmysql側から通貨を表すためにどのようなタイプを使用すべきですか?ここmysql float型
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try{
//collect arguments
String category = this.jTextField8.getText();
String pattern=this.jTextArea1.getText();
String color=this.jTextArea2.getText();
float price = Float.valueOf(this.jTextField14.getText()).floatValue();
float deposit = Float.valueOf(this.jTextField15.getText()).floatValue();
//create new order
int row=this.customerSelectedRow;
Order newOrder=new order(this.customerModel.dataVector.get(row),category,pattern,color,price,deposit);
newOrder.search();
//refresh
this.jDialogNewOrder.setVisible(false);
}catch(Exception e){
System.err.println (" Error message: " + e.getMessage());
}
}
あなたは浮動小数点値との通貨での検索方法
try {
s = c.conn.prepareStatement("SELECT id FROM `"+this.table+
"` WHERE customerId=? AND category=? and pattern=? and color=? and deposit=? and price=?");
s.setInt(1,this.customer.getId());
s.setString (2, this.category);
s.setString (3, this.pattern);
s.setString (4, this.color);
s.setFloat(5,this.deposit);
s.setFloat(6,this.price);
System.err.println(s.toString());
ResultSet res = s.executeQuery();
System.out.println("printing ids :");
while (res.next()) {
int i = res.getInt(1);
//assigning the correct id to the inserted customer
this.id=i;
System.out.println("id" + "=" + i);
}
} catch (SQLException e) {
System.err.println ("find id Error message: " + e.getMessage());
System.err.println ("find id Error number: " + e.getErrorCode());
非常に良い答えです。 :-) –