Data truncation: Data too long for column

I have checked the length of my data and it is varchar 50. And still I am getting this error. Please let me know where I could have gone wrong.

Error: Data truncation: Data too long for column ‘RegistrationNo’

   DBConnection conn = new DBConnection();

    String query = ("INSERT INTO registration(RegistrationNo,firstName,lastName,NIC,Address,District,Gender,DateofBirth,MobileNo,EmailAddress,Programme,Center,Year,guradianName,guardianRelation,guardianAddress,Contact) values('"+registrationText+"', '"+firstNameText+"' ,'"+lastNameText+"','"+nicText+"','"+addressText+"','"+districtText+"', '"+genderCombo+"' ,'"+birthText+"','"+mobileText+"','"+emailText+"', '"+programmerText+"', '"+centerText+"' ,'"+yearText+"','"+guradiannameText+"','"+relationText+"','"+guradianaddText+"', '"+guardiancontactText+"')");
    try {
        //PreparedStatement st=conn.getConnection().prepareStatement(query);
        Statement st=conn.getConnection().createStatement();
        //PreparedStatement p = conn.getConnection().prepareStatement(query);
        st.executeUpdate(query);
    } catch (ClassNotFoundException | SQLException ex) {
        Logger.getLogger(Registration.class.getName()).log(Level.SEVERE, null, ex);
    }


Source: sql

Leave a Reply