i m using gettext() method in getting text from the form and pass it to the sql query to record in the mysql database. when i don't enter any string for textfield (for eg: phone no.) , i get sql exception error..

here is my sql query in the code..

String query= "INSERT INTO Table1( PatName, Dob, PatGender, PatAddress, PatPhoneno, PatMobile, PatRelative, Relation, AdmissionDate, DischargeDate, ClinicalFeature, Diagnosis, Treatment, Followup ) VALUES ('"+
                    txtPatName.getText() + "','"+                          
                    txtyear.getText()+"-"+txtmth.getText()+"-"+txtday.getText() + "','"+
                    (String)PatGender.getSelectedItem() + "','"+
                    txtPatAddress.getText() + "','"+
                    txtPhone.getText() +"','"+
                    txtMob.getText() +"','"+
                    txtRelname.getText() +"','"+
                    txtRelation.getText() +"','"+
                    txtAdmissiondate.getText() +"','"+
                    txtDischargedate.getText() +"','"+
                    txtclinical.getText() +"','"+
                    txtDiagnosis.getText() +"','"+
                    txtTreat.getText() +"','"+ 
                    txtFollowup.getText()+ "')";

can anyone help to solve how to solve this problem????

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

its in a JTextField class..
i m using it in my AddFrame class.
i think its problem created by not giving any string value in JTextField.
and when i click add record button.. it gives sql exception error

it says i have given wrong value in the field where actually i hav not given any value

If you need a non empty String value, you should get the text and check it before using it.

JTextField.getText() will always return a String. I might have a length() of 0 but will never be null

I don't know for sure...
But, it sounds like the SQL is what is failing.
If the column is a required column, and you pass a null string/value, your Insert statement will fail.

yeah u r right hfx642.. its a sql error.. insertion is failing due to passing of null string value..
and how do i correct it?

This article has been dead for over six months. Start a new discussion instead.