private void eaddbtnActionPerformed(java.awt.event.ActionEvent evt) {                                        

        if(eaddbtn.getText().equals("Add")){

            eaddbtn.setText("Save");
            eupbtn.setVisible(false);
        //  edeletebtn.setVisible(false);
            ecanbtn.setText("Cancel");
        }

        else{

            Enrollment e = new Enrollment(eid_txt.getText(),ecode_txt.getText(),egrade_txt.getText() , emarks_txt.getText() );  // ERROR APPEARS IN HERE

            e.SaveEnrollment();
        }
    }

i want to add int value to mysql database...how can i do that?
how to convert int value to string value...

here is my enrollment class...

public class Enrollment {

    private String student_id;
    private String subject_code;
    private String Grade;
    private int Marks;

    Enrollment(String student_id,String subject_code,String Grade, int Marks){

        this.student_id = student_id;
        this.subject_code = subject_code;
        this.Grade = Grade;
        this.Marks = Marks;
    }


    public String getGrade() {
        return Grade;
    }


    public void setGrade(String Grade) {
        this.Grade = Grade;
    }

    public int getMarks() {
        return Marks;
    }


    public void setMarks(int Marks) {
        this.Marks = Marks;
    }

        public String getStudent_id() {
        return student_id;
    }


    public void setStudent_id(String student_id) {
        this.student_id = student_id;
    }


    public String getSubject_code() {
        return subject_code;
    }


    public void setSubject_code(String subject_code) {
        this.subject_code = subject_code;
    }


    public boolean SaveEnrollment()
    {
        try{
            DatabaseCon.update("INSERT INTO enrollrd(student_id, subject_code,marks, grade) VALUES('" + student_id +"','"+ subject_code +"' ,'" + Marks + "' ,'"+Grade + "')");
            return true;
            }

         catch (Exception e) {
         e.printStackTrace();
         return false;
        }
    }

 


}

i'm lost in here..pls help me...
thanks in advance!

Actually you need to convert String to int. If this: emarks_txt is a JTextFiled then this: emarks_txt.getText() returns String. But your Enrollment constructor takes as argument an int:
Enrollment(String student_id,String subject_code,String Grade, int Marks)

So you can do this:

int Marks = Integer.parseInt(emarks_txt.getText());

Enrollment e = new Enrollment(eid_txt.getText(),ecode_txt.getText(),egrade_txt.getText() , Marks );

Or better:

try {
     int Marks = Integer.parseInt(emarks_txt.getText());

     Enrollment e = new Enrollment(eid_txt.getText(),ecode_txt.getText(),egrade_txt.getText() , Marks );

     e.SaveEnrollment();
} catch (NumberFormatException nfe) {
      System.out.println("Error. Mark entered not a number: " + nfe.getMessage());
       // OR
     JOptionPane.showMessageDialog(null, "Mark entered not a number")
}
commented: thanks :) scrathwiz.. +1

thanks javaAddict :D :D

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.