【发布时间】:2016-11-23 10:09:52
【问题描述】:
用新文件更新附件字段后,mysql文件路径没有斜杠。谁能告诉我修复它的路径?
这是我的文件附件按钮:
private void attachActionPerformed(java.awt.event.ActionEvent evt){
JFileChooser chooser=new JFileChooser();
chooser.showOpenDialog(null);
File f=chooser.getSelectedFile();
String file=f.getAbsolutePath();
file_attach.setText(file);
}
这是我的更新按钮代码:
private void update_fieldsActionPerformed(java.awt.event.ActionEvent evt){
try{
String add1=course_catergory.getSelectedItem().toString();
String add2=code_course.getText();
String add3=course_type.getSelectedItem().toString();
String add4=course_name.getText();
String add5=file_attach.getText();
String sql="UPDATE course SET category='"+add1+"' ,course_code='"+add2+"' ,course_type='"+add3+
"' ,course_name='"+add4+"' ,attach_file='"+add5+"' where course_code='"+add2+"' ";
pst=conn.prepareStatement(sql);
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Successfully updated.");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
update_course_table();
}
【问题讨论】:
-
了解准备好的语句
-
好的。非常感谢。