unreported exception java.sql.SQLException; must be caught or declared to b
807601Jan 10 2008 — edited Jan 11 2008I dont know much about java Please help.
I have created following class
import java.sql.*;
public class Updatedb{
private String cofeename ;
private int supid;
public void getfields(String COFNAM , int SUP_ID){
cofeename = COFNAM;
supid = SUP_ID;
}
public void indb()
throws SQLException {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DriverManager.getConnection("jdbc:odbc:myDataSource");
pstmt = con.prepareStatement(
"UPDATE COFFEES SET SUP_ID = " + supid + "WHERE COF_NAME =" + cofeename );
//pstmt.setInt(1, SUP_ID);
//pstmt.setInt(2, COFNAM);
pstmt.executeUpdate();
}
finally {
if (pstmt != null) pstmt.close();
}
}
}
Now I am calling above class when button is clicked
private void UPDATEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UPDATEActionPerformed
// TODO add your handling code here:
String input = INPUTFIELD.getText();
Updatedb updateclass = new Updatedb();
updateclass.getfields(input , 20);
updateclass.indb( );
INPUTFIELD.setText( "" );
}
I am getting above error. Please help me to solve it.
Thanks in advance