-1

I want to Update a database and want to put the Numbers like this: 1.384,38

Here is my Code to Update from the Textfield but it doesn't work

try {
                String query="Update Sina Set Iuuiu = ?  where Formate = ? " ;


                PreparedStatement pst=connection.prepareStatement(query);
                pst.setDouble(1, Double.parseDouble(textField_3.getText()));  

                pst.setString(2, "Zuschnittentnahme Gegensauger"); 

                pst.executeUpdate();


                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }

This is my Code. Now I have to type it like this: 1344.43 but I want to type it like this: 1.344,43

Sonaldo
  • 1
  • 1
  • 2
    We'd need a little more context, e.g.: Why do you want to store numbers as strings? What does your update code/query look like? What exacly "doesn't work"? - In general please read [ask] and then update your question accordingly. – Thomas Aug 20 '19 at 14:11
  • `format(pst.setDouble(...))` what exactly are you trying to do here? Do you realize that `PreparedStatement.setDouble()` doesn't return anything, i.e. `void`? – Thomas Aug 20 '19 at 14:13
  • Maybe [this answer](https://stackoverflow.com/a/50543/11905620) might help you concerning number formatting. – MaS Aug 20 '19 at 14:17

1 Answers1

0

To parse a number in your default locale use

String text = textField_3.getText();
double number = NumberFormat.getInstance().parse(text).doubleValue();
pst.setDouble(1, number);

or using a given locale:

String text = textField_3.getText();
double number = NumberFormat.getInstance(Locale.GERMANY).parse(text).doubleValue();
pst.setDouble(1, number);

don't forget a try-catch for the eventual ParseException thrown by parseDouble

user85421
  • 28,957
  • 10
  • 64
  • 87