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????

What class is the getText() a method in?
What does the API doc say?

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.

and how do u check the value?

See if its length is 0.

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

Member Avatar for hfx642

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?

Find which method or variable's value is null and change it to a non-null value.

Or change the table column to allow null if that is appropriate for your data.

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.