It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Daniel Demesmaecker wrote:What isn't working? Anny errormessages? I can tell you this in advance: That's not how you create a prepared statement...
Have a look at how it's done
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Daniel Demesmaecker wrote:If your data is shown the statement isnt the prob. For the formatting this should do the trick:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
... 56 more
Caused by: java.util.UnknownFormatConversionException: Conversion = ','
at java.util.Formatter.checkText(Formatter.java:2579)
at java.util.Formatter.parse(Formatter.java:2565)
at java.util.Formatter.format(Formatter.java:2501)
at java.util.Formatter.format(Formatter.java:2455)
at java.lang.String.format(String.java:2940)
at loginfx.InvoiceContoller.GrandSum(InvoiceContoller.java:193)
at loginfx.InvoiceContoller.getBillNo(InvoiceContoller.java:86)
at loginfx.NewOrderController.ShowBillInvoice(NewOrderController.java:602)
... 66 more
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Daniel Demesmaecker wrote:You could use a pattern to format your number.
De poundsigns represent a nr. De comma is your seperator and the point your decimal sign. SO now you have every three nrs a seperator and two decimal points (there only 2 pound signs at the end)
Note : that you will have to parse your String to a long before formatting. Dont forget the L on the end
Sorry if the explenation isn't that clear, but I don't really know how to explain in english
Please always copy'n'paste your code; you have introduced two compiler errors into line 2, but I am 99% sure they weren't in the original.Ifraz Imanudeen wrote:. . .. . .
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Campbell Ritchie wrote:
Please always copy'n'paste your code; you have introduced two compiler errors into line 2, but I am 99% sure they weren't in the original.Ifraz Imanudeen wrote:. . .. . .
I can see other errors in that code: why are you storing numbers as Strings in your database? Surely you would store money as a DECIMAL(8, 2) or similar; that will allow any amount < £$₹€₽¥1000000, I think. Then you get the result from the result set as a BigDecimal (I think).
Then I am not sure whether you are using formatters or decimal format. When Formatter was introduced in 2004, I was told that it is no longer necessary to use decimal format and similar, and I have believed that. So what I would do is thisThe comma means to use the thousands separator appropriate to that Locale, and .2f means to format it as a fixed‑point (decimal) number with two digits after the decimal point. If you look up String#format(), you will find that the Locale is optional because the method is overloaded.
[edit]Correct spelling errors and add “String.format(...)”.
Dave Tolls wrote:
Ignoring the typos for the moment, this is assuming you are getting a long value from the 1st column in your ResultSet.
...
It is failing because the value in the column is 2335.0, which is not a valid long.
And Campbell is quite correct, why on earth is your database storing numbers as a String?
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Daniel Demesmaecker wrote:
Why do you think he's suppose to get a long? He's getting a String and trying to parse it to a long.
Daniel Demesmaecker wrote:
I also often store a number as a String, as long you don't have to do calculations with it, what does it mather?
Dave Tolls wrote:
It's because he's parsing it as a long that means he needs a long to start with.
That's the error.
That String does not contain a long...it's a float of some description.
Dave Tolls wrote:
It's a number, so it should be treated as such, otherwise you get these problems.
There should be no need to parse a number retrieved from the database.
It's the same problem as storing DATEs as VARCHAR, or phone numbers as NUMBER when they're VARCHARs.
Store the data as the type it represents then you don't have to jump through hoops later on to actually use it.
In addition, you also get the correct ordering for the column if it's a NUMBER.
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Daniel Demesmaecker wrote:
He dosn't start with a long, he start with a string, it should just be parseable to a long, but it always be a String
Daniel Demesmaecker wrote:
I wasn't saying he should store at as a string in this case, but a housenr in an address for example, what does it mather if it's a number or a String
Dave Tolls wrote:
Ignoring the typos for the moment, this is assuming you are getting a long value from the 1st column in your ResultSet.
The error, however, shows this:
Caused by: java.lang.NumberFormatException: For input string: "2335.0"
at java.lang.NumberFormatException: For input string(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
This has nothing to do with the DecimalFormat, as your code doesn't even get to the line where that is used.
It is failing because the value in the column is 2335.0, which is not a valid long.
And Campbell is quite correct, why on earth is your database storing numbers as a String?
If you don't do calculations, then it isn't a number. A house number, a national insurance/social security number, or a phone number are not numbers in that sense, as Dave has already said; you don't do any arithmetic with them. But storing genuine numbers as Strings is often wasteful in memory because Strings occupy more space, and error‑prone because you can't be sure that you have stored the correct format for a number. Also, you have the overhead of encoding the number as a String and decoding it later with the parseXXX method.Daniel Demesmaecker wrote:. . . as long you don't have to do calculations with it, what does it mather?
[pedantic mode]You mean the String is the text representation of a double, as opposed to the text representation of a long.[/pedantic mode]Dave Tolls wrote:. . . But the String is a double . . .
Campbell Ritchie wrote:[pedantic mode]You mean the String is the text representation of a double, as opposed to the text representation of a long.[/pedantic mode]
Campbell Ritchie wrote:
Maybe you should consider a different database. The only datatype it has suitable for money appears to be INTEGER.Ifraz Imanudeen wrote:. . . SQLite
Which has very few data types. . . .
Campbell Ritchie wrote:
Maybe you should consider a different database. The only datatype it has suitable for money appears to be INTEGER.Ifraz Imanudeen wrote:. . . SQLite
Which has very few data types. . . .
No, I said INTEGER, which is what the link I posted earlier said. As Dave has told you, you will be storing the data in cents/pence etc and will need % 100 and / 100 to convert it. Maybe there are different names for integers, like INT, LONG_INT etc.Ifraz Imanudeen wrote:. . . Did you say integer . . .
Campbell Ritchie wrote:
No, I said INTEGER, which is what the link I posted earlier said. As Dave has told you, you will be storing the data in cents/pence etc and will need % 100 and / 100 to convert it. Maybe there are different names for integers, like INT, LONG_INT etc.Ifraz Imanudeen wrote:. . . Did you say integer . . .
Dave Tolls wrote:But remember, as an Int the data will now be in pennies (or cents, or whatever the smaller unit is) and not pounds (or euros, or dollars).