Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Statement Help

Status
Not open for further replies.

crguy

Programmer
May 24, 2001
34
CA
I have the following method, what I don't understand is how I need to process the statement. Can anybody direct me on how to do this?

Thanks

public void updateStudentInformation(StudentInformation stInformation) throws Exception {
if (conn != null) {
try {
PreparedStatement ps;
ps = conn.prepareStatement(
"UPDATE STUDENT_INFORMATION " +
"SET " +
"LANGUAGE1 = ? " +
",WR_LANG1 = ? " +
",SP_LANG1 = ? " +
",LANGUAGE2 = ? " +
",WR_LANG2 = ? " +
",SP_LANG2 = ? " +
",LANGUAGE3 = ? " +
",WR_LANG3 = ? " +
",SP_LANG3 = ? " +
",CAR = ? " +
",PDSB = ? " +
",DATE_MODIFIED = (SELECT SYSDATE FROM DUAL) " +
"WHERE STUDENT_ID = ? ");

ps.setInt(1, stInformation.getLanguage1());
ps.setInt(2, stInformation.getWritingLanguage1());
ps.setInt(3, stInformation.getSpokenLanguage1());
ps.setInt(4, stInformation.getLanguage2());
ps.setInt(5, stInformation.getWritingLanguage2());
ps.setInt(6, stInformation.getSpokenLanguage2());
ps.setInt(7, stInformation.getLanguage3());
ps.setInt(8, stInformation.getWritingLanguage3());
ps.setInt(9, stInformation.getSpokenLanguage3());
ps.setString(10, stInformation.getCar());
ps.setString(11, stInformation.getPDSB());
ps.setInt(12, stInformation.getID());
ps.execute();

} // End try
catch (SQLException sqle) {
error = "SQLException: update failed.";
throw new SQLException(error);
}
}
else {
error = "Exception: Connection to database was lost.";
throw new Exception(error);
}
}// End updateStudentInformation
===========================================================
public class StudentInformation {

public int lang1;
public int wr_lang1;
public int sp_lang1;
public int lang2;
public int wr_lang2;
public int sp_lang2;
public int lang3;
public int wr_lang3;
public int sp_lang3;
public String car;
public String pdsb;
public int id;

// Language 1
public int getLanguage1() {
return lang1;
}

public int getWritingLanguage1() {
return wr_lang1;
}

public int getSpokenLanguage1() {
return sp_lang1;
}

// Language 2
public int getLanguage2() {
return lang2;
}

public int getWritingLanguage2() {
return wr_lang2;
}

public int getSpokenLanguage2() {
return sp_lang2;
}

// Language 3
public int getLanguage3() {
return lang3;
}

public int getWritingLanguage3() {
return wr_lang3;
}

public int getSpokenLanguage3() {
return sp_lang3;
}

// Car
public String getCar() {
return car;
}

// PDSB
public String getPDSB() {
return pdsb;
}

// ID
public int getID() {
return id;
}

}
 
You have to create a new Instance of your StudentInformation class at first and the use this class in your method.

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
 
Hi Salih,

Can you please provide an example? I am getting confused about this.

Thanks
 
Let us think.
We have an update method which updates student informations,to update the student informations you have a class named StudentInformation.
Most probably, your update method is an other class.Lets say ClassA to this.
In order to use these 2 classes you have to create new instances of that classes.
....
ClassA varA = new ClassA();
StudentInformation si = new StudentInformation();
//with these 2 sentences you create a new instance and are
// ready to use them...
//now you should fill the fields of StudentClass.
//and as far as I see you don't have setter methods.You
// have only getter methods...
si.id=5;
si.car="Opel Astra";
......
//etc.
//after you are sure you fill the information, all you have
// to do is :
varA.updateStudentInformation(si);

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
 
Hi Salih,

I am sorry for all the questions.

I have a method (updateStudentInformation) and a class (StudentInformation). Where do I need to create a new instance, in my StudentInformation class? Also, my values for si.id come from a database so I am not sure what I need to put for si.id = 5. I assume I can then use varA.updateStudentInformation(si); in my JSP page.

Thanks for all your help.
Vito
 
I know you'd ask that question?
Well as a start do u manage read your records from the database and fill your StudentInformation class?

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
 
Hi,

I manage to read the records fine. I am not sure about filling in my StudentInformation class.

Thanks
Vito
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top