I want to update my database but the problem is that the driver is not taking any values from the preparedStatement.
I am getting an error :
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] You must enter a value in the 'ClassicRoom.Occupy' field.
Press any key to continue...
Here is the ActionPerformed code :
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(str.equals("Save"))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("JDBC:ODBC:HotelT");
PreparedStatement st=null;
if(room.getSelectedItem()=="Classic Rooms")
{
for(int j = 0; j < checkList.size(); j++)
{
JCheckBox cb = checkList.get(j);
if(cb.isSelected())
{
st=con.prepareStatement("update ClassicRoom set Occupy = ? AND RegNo = ? where RoomNo = ?");
st.setInt(1,1);
st.setInt(2,Integer.parseInt(reg_no.getText()));
st.setInt(3,Integer.parseInt(cb.getText()));
st.executeUpdate();
}
}
}
st.close();
con.close();
}
Catch(Exception e)
{
System.out.println(e);
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("JDBC:ODBC:HotelT");
int val=Integer.parseInt(reg_no.getText());
String val1=name.getText();
String val2=addr.getText();
String val3=tel.getText();
String val4=date_in.getText();
String val5=room.getSelectedItem();
int val6=Integer.parseInt(adult.getSelectedItem());
int val7=Integer.parseInt(child.getSelectedItem());
int val8=Integer.parseInt(no_rooms.getText());
String val9="";
for(int i = 0; i < checkList.size(); i++){
JCheckBox cb = checkList.get(i);
if(cb.isSelected()){
val9 += cb.getText();
val9 += ",";
}
}
//String val9=roomno.getSelectedItem();
//String b="insert into entry values ("+val+","+val1+",'"+val2+"','"+val3+"','"+val4+"','"+val5+"',"+val6+")";
// int exe=st.executeUpdate(b);
// String s="full";
// b="update room set state='"+s+"',regno="+val+" where room="+val1+" ";
// exe=st.executeUpdate(b);
PreparedStatement pst=con.prepareStatement("insert into Check_In values (?,?,?,?,?,?,?,?,?,?)");
pst.setInt(1,val);
pst.setString(2,val1);
pst.setString(3,val2);
pst.setString(4,val3);
pst.setString(5,val4);
pst.setString(6,val5);
pst.setInt(7,val6);
pst.setInt(8,val7);
pst.setInt(9,val8);
pst.setString(10,val9);
pst.executeUpdate();
pst.close();
con.close();
setVisible(false);
Menu a=new Menu();
}
catch(Exception e)
{
System.out.println(e);
}
}
if(str.equals("Menu"))
{
setVisible(false);
Menu b=new Menu();
}
if(str.equals("Exit"))
{
System.exit(0);
}
}
Note: while the below statement for insert works just fine.... but the above update statement does not work... I have been banging my head coz the syntax seems correct for prepared statement plz Help... Its Urgent...