Hi I am new in java. I am trying to get the stored date in the database and display the same in jdatepicker in frontend. But I failed. Can any one of you suggest how to do the same.

Regards
Sandeep

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

Hi this are the codes which I have written for a desktop application on Insurance domain. It actually finds the data from the database and displays in the fields but my pproblem as I said that I am using JDatepicker for date fields and unable to display the date in the field while trying to modify the data.

JButton btnModify = new JButton("MODIFY");
        springLayout.putConstraint(SpringLayout.NORTH, btnAdd, 0, SpringLayout.NORTH, btnModify);
        springLayout.putConstraint(SpringLayout.EAST, btnAdd, -23, SpringLayout.WEST, btnModify);
        springLayout.putConstraint(SpringLayout.WEST, btnModify, 202, SpringLayout.WEST, frame.getContentPane());
        btnModify.setMnemonic('M');
        btnModify.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae) 
            {
                try
                {
                    JTextField txtGetUserName=new JTextField(15);
                    JTextField txtGetUserID=new JTextField(15);
                    JTextField txtGetLiscenseCode=new JTextField(15);

                    JPanel ModifyPanel=new JPanel();
                    ModifyPanel.add(new JLabel("User Name : "));
                    ModifyPanel.add(txtGetUserName);
                    ModifyPanel.add(new JLabel("User ID : "));
                    ModifyPanel.add(txtGetUserID);
                    ModifyPanel.add(new JLabel("Liscense Code : "));
                    ModifyPanel.add(txtGetLiscenseCode);
                    int response=JOptionPane.showConfirmDialog(frame,ModifyPanel,"Modification Entry Menu",JOptionPane.OK_CANCEL_OPTION);
                    if(response==JOptionPane.CANCEL_OPTION)
                    {
                        btnUpdate.setVisible(false);
                        btnModify.setVisible(true);
                        JOptionPane.showMessageDialog(null, "You either did not entered data in the fields OR Cancelled the operation.");
                        txtUserName.requestFocus();
                    }
                    else
                    {
                        try
                        {
                            DB_Connection dbcon=new DB_Connection();
                            dbcon.DB_Connection("//F://eclipse_Luna_64//Project JAVA//LIC_AGENCY_TRACKER//DATABASE//LIC_DATA_TRACKER.accdb");

                            String getusername=txtGetUserName.getText().toUpperCase();
                            String getuserid=txtGetUserID.getText();
                            String getliscensecode=txtGetLiscenseCode.getText();

                            if(getusername.length()!=0 || getuserid.length()!=0 || getliscensecode.length()!=0)
                            {
                                Statement stmt=dbcon.DB_Connection("//F://eclipse_Luna_64//Project JAVA//LIC_AGENCY_TRACKER//DATABASE//LIC_DATA_TRACKER.accdb").createStatement();
                                ResultSet rset=stmt.executeQuery("select * from User_Profile where User_Profile_Name='"+getusername+"' or User_Profile_Login='"+getuserid+"' or USer_Profile_LIC_Liscence_Code='"+getliscensecode+"'");
                                while(rset.next())
                                {
                                    txtUserName.setText(rset.getString("User_Profile_Name"));
                                    txtDesignation.setText(rset.getString("User_Profile_Designation"));
                                    txtUserID.setText(rset.getString("User_Profile_Login"));
                                    txtPassword.setText(rset.getString("User_Profile_Password"));
                                    txtConfirmPassword.setText(rset.getString("User_Profile_Confirm_Password"));
                                    txtLICBrCode.setText(rset.getString("User_Profile_LIC_Branch_Code"));
                                    txtLICAgencyCode.setText(rset.getString("User_Profile_LIC_Agency_Code"));
                                    txtLICLiscenceCode.setText(rset.getString("USer_Profile_LIC_Liscence_Code"));

                                    String getsdate=rset.getString("User_Profile_LIC_Liscence_Start_Date");
                                    String getdate[]=getsdate.split("-");
                                    SimpleDateFormat smf=new SimpleDateFormat("dd");
                                    Date getDDate=smf.parse(getdate[0]);
                                    int dd=Integer.valueOf(getdate[0]);
                                    smf=new SimpleDateFormat("MM");
                                    Date getMDate=smf.parse(getdate[1]);
                                    int mm=Integer.valueOf(getdate[1]);
                                    smf=new SimpleDateFormat("yyyy");
                                    Date getYdate=smf.parse(getdate[2]);
                                    int yy=Integer.valueOf(getdate[2]);
                                    System.out.println(dd+","+mm+","+yy);
                                    utilDateModel=new UtilDateModel();
                                    utilDateModel.setDate(yy,mm,dd);
                                    utilDateModel.setSelected(true);
                                    JDatePanel=new JDatePanelImpl(utilDateModel, p);
                                    txtLiscenceStartDate = new JDatePickerImpl(JDatePanel,new DateLabelFormatter());
                                    txtLiscenceStartDate.repaint();

                                    String getedate=rset.getString("User_Profile_LIC_Liscence_Expiry_Date");
                                    String getdate1[]=getedate.split("-");
                                    int dde=Integer.valueOf(getdate1[0]);
                                    int mme=Integer.valueOf(getdate1[1]);
                                    int yye=Integer.valueOf(getdate1[2]);
                                    utilDateModel=new UtilDateModel();
                                    utilDateModel.setDate(yye,mme,dde);
                                    utilDateModel.setSelected(true);

                                    btnModify.setVisible(false);
                                    btnUpdate.setVisible(true);
                                }   
                            }
                        }
                        catch(Exception e)
                        {
                            JOptionPane.showMessageDialog(null,"You have cancelled the operation","Message",JOptionPane.INFORMATION_MESSAGE);
                        }
                    }
                }   
                catch(Exception e)
                {
                    JOptionPane.showMessageDialog(null,"You have cancelled the operation","Message",JOptionPane.INFORMATION_MESSAGE);
                    txtUserName.requestFocus();
                }
            }
        });

        btnModify.setFont(new Font("Times New Roman", Font.BOLD, 11));
        frame.getContentPane().add(btnModify);

Regards
Sandeep

Hi friends till now I am unable to solve the above issue. Can anyone please advice / suggest me how to solve the issue.... Waiting for you help...

Regards
Sandeep

I don't use JDatePicker, but if nobody else wants to have a go...

This isn't a part of the standard Java distribition, so your best source for support is its development team http://jdatepicker.org/2012/10/20/about-jdatepicker-and-jdatepanel/
It says you can use an SQL.date for the model, so maybe that's the simplest/best way to go?

  • assuming to store value as Date, TimeStampt in database

  • you have to use ResultSet.getDate() instead of little bit crazy parsing and then formatting String instance ...

  • every JDatePickers/JCalendar has setValue/Date(Date/Calendar),

  • every good JDatePickers/JCalendar has own FAQs with code examples

  • SpringLayout isn't good LayoutManager for newbee

  • (major issue) don't to create a new Swing Object in try-catch-finally, and you have to notify (to revalidate and repaint for container == JPanel) LayoutManager (thanks that is not implemented as automatical processing) about changes (new JComponent is removed, added, etc) to already visible Swing GUI

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.