0

I need to choose a date from my datepicker and i need to submit that date to my database(mysql). Previously I have used textfield for the date and i got the the expected output. Now i need to use datePicker,How to use my datePicker to submit my selected date to the mysql database? Thanks in advance,any suggestions would be appreciable I have created my calendar by using this four lines:

UtilDateModel model1 = new UtilDateModel();
     JDatePanelImpl datePanel = new JDatePanelImpl(model1);
     JDatePickerImpl datePicker = new JDatePickerImpl(datePanel,new DateLabelFormatter());
     datePicker.setBounds(130, 130, 180, 20);

Below is my query,that i have used date as a textfield:

theQuery("insert into Files5(FileName,LinesCount,UserId,Date,Time) values('"+JT_FileName.getText()+"','"+JT_LinesCount.getText()+"','"+JT_UserId1.getText()+"','"+JT_Date1.getText()+"','"+JT_Time1.getText()+"')");

Now how can i replace my JT_DATE1 with my datePicker

Digvijaysinh Gohil
  • 1,367
  • 2
  • 15
  • 30
vasanth
  • 15
  • 8
  • 1. Use `PreparedStatement` - it will allow you to pass object based data to the query, rather then `String`s; 2. I recommend using the `SqlDateModel` instead; 3. Use `datePicker.getModel().getValue()` return the currently selected date – MadProgrammer Nov 28 '17 at 04:35
  • okay let me try and thanks @MadProgrammer – vasanth Nov 28 '17 at 04:44
  • @MadProgrammer, Actually i m new to the database and i m stuggling to convert the statement into the prepared statement and i dont have any idea. – vasanth Nov 28 '17 at 05:00
  • [Using Prepared Statements](https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html) – MadProgrammer Nov 28 '17 at 05:01
  • thanks once again i will refer the above site – vasanth Nov 28 '17 at 05:03
  • Data Truncation:Incorrect date Value:for column 'Date' at row 1 – vasanth Nov 28 '17 at 05:31
  • i got this error message @MadProgrammer – vasanth Nov 28 '17 at 05:31
  • Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). – Andrew Thompson Nov 28 '17 at 05:34
  • Using what query? – MadProgrammer Nov 28 '17 at 05:35
  • PreparedStatement pstm = con.prepareStatement("SELECT * FROM Files5 where Date=? "); – vasanth Nov 28 '17 at 05:36
  • i don't have any problem with my gui @AndrewThompson – vasanth Nov 28 '17 at 05:46
  • PreparedStatement pstm = con.prepareStatement("SELECT * FROM Files5"); ResultSet Rs = pstm.executeQuery(); while(Rs.next()){ Vector row = new Vector(); row.add(Rs.getString("FileName")); row.add(Rs.getInt("LinesCount")); row.add(Rs.getString("UserId")); row.add(Rs.getString("Date")); row.add(Rs.getString("Time")); data.add(row); – vasanth Nov 28 '17 at 07:54
  • my whole query part @MadProgrammer – vasanth Nov 28 '17 at 07:55
  • *"i don't have..:* What about the **next** user using a different screen size, screen resolution.. (etc.). If this program is only for you (with all those other things locked in) it's not going to be a problem. – Andrew Thompson Nov 28 '17 at 08:09
  • sorry @AndrewThompson – vasanth Nov 28 '17 at 08:34
  • waiting for your comment@MadProgrammer – vasanth Nov 28 '17 at 09:52

0 Answers0