Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

unreported exception java.sql.SQLException; must be caught or declared to b

807601Jan 10 2008 — edited Jan 11 2008
I 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 8 2008
Added on Jan 10 2008
2 comments
511 views