I’m developing a program that prompt the user to select time for his/her stay on the hotel, and i’m using a JSpinner to do this. But i don’t know how to extract time from JSpinner and insert it to MySQL database on the time format. Please help and give me some example. Sorry for noob question
Share
JSpinner#getValue) and convert it to a time object. The conversion will depend on what data is stored in your spinner model. TheSpinnerDataModelmight be an interesting model to back your spinner,Runnableand using a newThreadto execute this.Examples can be found in the
JSpinnertutorial. For example (copy pasted from that tutorial) if you use theSpinnerDateModel, you can usewhich allows you to retrieve a
Dateobject directly from the model, without a conversion.Further, the Swing concurrency tutorial explains why you should update your db on a background thread. It also contains code snippets on how to execute something on a background thread from the EDT. But in case you simply need to update the db, and nothing in the UI must be updated, there is not much need to opt for the
SwingWorkerclass which is used in that sample code. In that case, you can simply start a newThreadas I stated above. The net is filled with examples on how to achieve that.