我有这个代码
earthid 是主键,这是我用来确保更新确切行的方法。
int row=jTable1.getSelectedRow();
String sql="UPDATE TB_EARTHORIENTATIONPARAMETER SET year="+year1+", month="+month1+", day="+day1+", mjd="+mjd1+",ut1utcdelta="+Ut1utc+" WHERE (earthid="+row1+")";
然而,当我执行这个语句时,什么也没有发生......数据库没有用新值更新我无法弄清楚我的 sql 更新语句有什么问题
好的,这是我的更新按钮后面的更多代码。
jTable1.getModel().addTableModelListener(jTable1);
DefaultTableModel model=(DefaultTableModel)jTable1.getModel();
int row=jTable1.getSelectedRow();
int row1=row+1;
int column=0;
String years="";
String months="";
String days="";
String mjds="";
String ut1utc="";
int year1;
int month1;
int day1;
double mjd1;
double Ut1utc;
while(column!=7)
{
Object year=model.getValueAt(row, column);
years=year.toString();
year1=Integer.parseInt(years);
column++;
Object Month=model.getValueAt(row, column);
months=Month.toString();
month1=Integer.parseInt(months);
column++;
Object Day=model.getValueAt(row, column);
days=Day.toString();
day1=Integer.parseInt(days);
column++;
Object MJD=model.getValueAt(row, column);
mjds=MJD.toString();
mjd1=Double.parseDouble(mjds);
column++;
Object UT1UTCDELTA=model.getValueAt(row,column);
ut1utc=UT1UTCDELTA.toString();
Ut1utc=Double.parseDouble(ut1utc);
column++;
try
{
DBConnectionclass cm=new DBConnectionclass();
String sql="UPDATE TB_EARTHORIENTATIONPARAMETER SET year="+year1+", month="+month1+", day="+day1+", mjd="+mjd1+",ut1utcdelta="+Ut1utc+" WHERE (earthorientationparameterid="+row1+")";
Connection con1=null;
Statement stmt=null;
con1=cm.getConnection(); //get a connection object
stmt=con1.createStatement();
stmt.executeUpdate(sql);
//create an instance of the database connection class to create a connection object to beused to conect to database
//create a statement to process sql query
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
// TOD
}
它不是编写代码的最佳方式,但它与 mysql 一起工作得很好。我需要选择更新吗