Tuesday, March 20, 2018

Use jdatechooser in java



This tutorial shows you how to use the JDateChooser open-source library in order to display a calendar component in Java Swing Application.  By default Netbeans donot have JDateChooser installed on the palette manager, so you need to download it.
To download JDateChooser click here. 
  • After the completion of Download, Extract the downloaded file.
  • Then open your Netbeans program and go to Palette and right click on it
  • Then click on Palette Manager
  • The downloaded file is a jar file so Click on Add From Jar button in the Palette Manager Window.
  • Provide the path where you have extracted the downloaded file
  • Then click on the lib folder
  • select jcalender and click on next
  • Then after there are different options available. All the options are not important to us. So just choose jDateChooser and click on next
  • Select any one folder where you want to place the JDateChooser in the palette and click finish
By this you are able to place JDateChooser in the Pallete.

Please watch the video because there are some task to be done beside code

Code to Use jdatechooser in java

For Save Button

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String date = sdf.format(date_chooser.getDate());
            pst.setString(7,date);



SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting.
 

For Displaying Date in jTable

 try{
                int srow = jTable_Display_User.getSelectedRow();
                Date date = new SimpleDateFormat("yyyy-MM-dd").parse((String)model.getValueAt(srow,6));
                date_chooser.setDate(date);
            }
             catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }


In order to to set date into JDate Chooser, you need to get the selected row from the jTable. After that you need to define the format how to place the date in the jdatechooser and finally you can set the date into jdatechooser.
For Update Button 

date_chooser.setDate(rs.getDate("date"));


Please don't forget To Like, Share and Subscribe my Youtube video and Channel.


Youtube Channel Subscription Click Here

This is how i speak in the video tutorial:
But every thing is genereted by youtube. so there may be some mistakes.




Today I'll show you how to use jdatechooser in this project so this is my previous project and I want to add jdatechooser in this project by default there is no datechooser installed  in the palette of this NetBeans so you need to download it so let us download the jdatechooser so type download J calendar it first download the J calendar click on that and scroll down the page and here we will find download the latest person latest version is . so click on Jcalendar here it will start to download the download is complete here so let me extract this click on yes I need the lib folder right click on it click on extract a specified folder so let me extract this on desktop click on ok so the extraction is completed here and let me close this program also and arrivee folder is here and here is a calendar which we need for a project so let me open the connecting program so we have to imported J calendar in this  palette so right click on the parent and click on palette manager so the downloaded file is desired file so click on it from Zac and go to the desktop click on li v MZ calendar  file which we are searching for so click on this one and you can next among them when you get a chisel so click on JDate scissor and click on next I will place the Sun so in control we can place it anywhere you can finish and click on close so Jake Jake's is our arrives here in the swing control so let me drag and drop this in the project here and let me split this a little bit and then after let me drag and drop our level here and write down get over here and let me change this variable name also latelyand now for inserting data I have created database earlier so let me open the gates were very first 

I have created a table which we store name address in the knowledge sorted and but I have to add a column distorter did also so for that let me expand this this TVand table right click on the table then after click on design and we need to insert a column here so write down a bit and anyone - it we did like it eight hours null so ctrl s to save it so we have created the database let me so you in by becoming sick got thousand roads so the gate is the date column is created with all the null values here so let me minimize this our database work is finished not now we have to perform the coding we have to write the code for date so double click on Save button so this is the coding that we have done earlier for say button which will insert  name it is gender knowledge subject and image in the database now your dad is missing so let me get get now so our column name is dead so let me play some date over here and values yes a question man one question mark now then after scroll down and every for this PhD that execute update whenever I talk the Colfer date so I believe simple date format for him ladies import a format first we'll get in later for might be here therefore then after one this you to read them on in capital deterred otherwise we'll get leader and big other you can lighting small little here you should write in a simulator once again capital letter n this will be simulator so let me import this it first add import for Java then after let me declare a string variable to store the date string data costume that's TF dot let us format it equal and if you format and our J tells you the name what is name get on the schedule a vacant properties and place it over here dot the texts which are gated.

   This is ten column then I draw the st dot set is  I will save the string into the database so st string and output six we have already done four amazing now the CB  and we have to provide it so this must go for inciting the you get into the database so let me show you by running whether it works or not whether it inserts did I in database or not so this is our window so let me provide some username here suppose you know what is Ivan Python and is a student of computer science and you get ap this one match between  guess whose name is live this dream is right now and click on save so the data is inserted successfully so let me show you the database also whether it is insert it or not I click on it you can select of thousand words so get   is inserted into the database so by this we are able to insert a database so again I'd like to display the date in the Z table also so for that we need to write the code again so for the gt we have to use a we have to write a code in user class so double click on user class then after we have to declare a string variable for taken facilities we get then after after the bite image write down what most often write down let it be string and again yeah he's got it costume it and it last year looking copy this Dez and get it you can get this much in the user class now I can go to this of this class and you can design again now I have to add a column over here right click  click on table contents then I have to click on column and all together here are   let me add a in a good column for date so that I can get over here update and Japan was so did a lights over here now to display the date in a table we have to display the data that is stored in the database way the program is open so for that let me add a little code over here it is a mirror also so comma is stuck okay very well miss so I have read it a little cold over here on the array list so then after in so user also I appear too cool so yeah let me copy this one so if you are confused over here you can watch my previous video I have explained it in a previous video also that if we get yeah you see I can handle game so this much code for displaying the Living Dead in the  so let me show you by running whether it is placement it or not okay I have got the heater and because I have one change the array this size here  for second object let me run it again and shows me that data which I have placed in a database so yeah the date and the date is displayed here when I click on the data it should be the date should be displayed in this Jacobs's are also so for that let me close this and start writing the code for displaying the Katie is a dead Susan so let me go to the design again and I'll click on the table and go to events and click on mouse and mouse key so we apply down the little code over here I put the image so for that we have to enclose that put in the try catch and block so for that let me write down try gets first copied case from somewhere else X yeah and like the head on some little bit code over a high block so first of all I need to do that select it close on select it go understood name of power T bodies making copies name of our table and here's a tip if you is it's Erica Rosie's click by the user that is tricked by the user again with me creator of Z dot did get equals to C by date format it using the same date permit that I have used well in siding with attack so let it be by my one and and but first write the string over here the after now as true come on and do up to five we have done I apply now for I comma  s  comma  and place a cynical on it last then after let me input this debt and again our literature the name copy this and paste it over here if you see whether it works or not I have inserted date and the date is displayed over here so let me show you whether the same is selected or not or if you clean you select it over here also so let me show you by inserting another data suppose suppose it was on the Python it means I'll miss this one click on save they put it in such as of this will you let me see me then you can have severe or not goatee arrives here and let me say for the date okay you like little and this one nice to be so it walks quietly okay the same Getty selective in that the taxes are also so this much Corinne for displaying the dating each other so fault update also let me design and click on object and yeah I have to add a little bit code question what this poor over here let me know how to put that I have you done earlier in the same course a button sounds familiar easy come here babies nice copy this and paste it under so Dakota execute update they step over our code over here  it is fine now they can save it with a litter box or not for the object is Update button okay and let me change stuff let me use the object button over here let me it's in the dated first and later month also be September selected you can update and it is architects of this field and can view the object it get over here will see say get over here also so this much code for the J Delta so thanks for watching

 

Search data in database using java


In this tutorial you will be able to learn to search the data based on symbol number using java

Please watch the video because there are some task to be done beside code

Code to Search data in database using java

  private void searchdataKeyReleased(java.awt.event.KeyEvent evt) {                                      
        // TODO add your handling code here:
         try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String url="jdbc:sqlserver://localhost:1433;databaseName=testdb;user=sa;password=orchid";
            Connection con = DriverManager.getConnection(url);
            String sql = "Select * from users where sno =?";
            PreparedStatement pst = con.prepareStatement(sql);
            pst.setString(1, searchdata.getText());
            ResultSet rs = pst.executeQuery();
            if(rs.next()){
                String setid = rs.getString("sno");
                sno.setText(setid);
               
                String setname = rs.getString("name");
                name.setText(setname);
                String setadd= rs.getString("address");
                address.setText(setadd);
                String sex = rs.getString("gender");
                 if(sex.equals("Male")){
                male.setSelected(true);
                 }
                   else{
                female.setSelected(true);
                 }
                String knowledge = rs.getString("knowledge");
                switch(knowledge){
                case "Java ":
                    coreJava.setSelected(true);
                    python.setSelected(false);
                    break;
                 case "Python ":
                    python.setSelected(true);
                    coreJava.setSelected(false);
                    break;
                 default:
                    coreJava.setSelected(true);
                    python.setSelected(true);
                    break;
                 }
                String subject1 = rs.getString("subject");
                 switch(subject1){
                case "Computer Science":
                    subject.setSelectedIndex(0);
                    break;
                case "Management":
                    subject.setSelectedIndex(1);
                    break;
                case "Humanities":
                    subject.setSelectedIndex(2);
                    break;
                case "Arts":
                    subject.setSelectedIndex(3);
                    break;
                case "Education":
                    subject.setSelectedIndex(4);
                    break;
                   
                     }
                date_chooser.setDate(rs.getDate("date"));
                byte[] img = rs.getBytes("images");
                ImageIcon imageIcon = new ImageIcon(new ImageIcon(img).getImage().getScaledInstance(lbl_img.getWidth(),lbl_img.getHeight(),Image.SCALE_SMOOTH));
                lbl_img.setIcon(imageIcon);
                person_image = img;
               
            }
         }
           catch(Exception e){
            JOptionPane.showMessageDialog(null,e);
        }
    }                                     

Please don't forget To Like, Share and Subscribe my Youtube video and Channel.


Youtube Channel Subscription Click Here

This is the text that i speak in the video.
The text may not be correct as it is generated by the translator.

welcome previously I have created a login form which meant the user provided data with database and this place whether the login credentials are married or not and today I'll show you without the text billion password field in the login form are empty or not so if user do not provide login credentials and directly click on sign in button it matches a database value and souls the message there is username and password not correct so in today's tutorial I'll show you without typing any data you should display message is username and password field is empty when user click on sign-in button so for that let me place two level for displaying the message as username and password finish empty so this is per username remove the text and change your schedule name also so now double click on the Sign In button to write the poor to check whether it is empty or not so you have to write before the type try cache block so let me see what is the name of ourtake speed and password field it is username and it is password so begin the coding if these are main that is our XP name is chaim if it is empty and there is another pillow the password field if we take for good the first time that's what means our pasture field name but it takes Jean nd then what we have to do is we have to display message a in the level is username is empty a password is empty so for that okay one this we use an interval level name so this will display the message is animate empty you know also so this will save only when both fill our empty so if user name is only empty after that occurs for that 

also so else if let me copy this from here okay empty after what message I should display is when user name is empty so display message in level on this condition I am that user name is empty in  password also written earlier and secure for password I have to display this message level in labor underscore password - password so if both fill are not empty and what I have to do is that you take it to that did I miss value so LC statement will run here so let me show you by running the code going to directly click on sign button which will display messages user name is empty and password is empty so when I provide it at this video then it will take now username a password is not correct but the lip the message in the devil is still in the window so when user types of data you should go away from so for that let me write the code so please click on design character right click on the text field then after go to events and go to Kien click on key released when the key is released the message should be removed from the label so for that may work other school indeed when the key is released the text should be the text field should be empty the actors password also I can find the password field go to events and go to key and click on released then after I done here leave all the school that's what dot text so let me show you guy running it once username is empty a password is nt let me provide username so the leave a message in the level is remove and whenever there are some pass filter the message in the level is city but again you may click on sign inverter so it is not correct so by this we can perform the coding yourself