JAVA程序 没有返回结果集 数据库中显示操作已经完成 会弹出对话框:没有返回结果集 请JAVA高手帮忙看下
importjavax.swing.*;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListe...
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
public class subjectupdate extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel s_no = new JLabel("科目编号");
JTextField tf_no = new JTextField();
JLabel s_name = new JLabel("科目名");
JTextField tf_name = new JTextField();
JLabel s_type = new JLabel("科目类型");
JTextField tf_type = new JTextField();
JButton btn_add = new JButton("修改");
JPanel pan = new JPanel();
ImageIcon image=new ImageIcon("images/subjectimage.jpg");
JLabel indexbackground=new JLabel(image);
subjectupdate() {
this.setBounds(100, 100, 500, 450);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLayout(null);
s_no.setBounds(100, 50, 70, 30);
tf_no.setBounds(200, 50, 100, 30);
s_name.setBounds(100, 100, 70, 30);
tf_name.setBounds(200, 100, 100, 30);
s_type.setBounds(100, 150, 70, 30);
tf_type.setBounds(200, 150, 100, 30);
btn_add.setBounds(200, 200, 100, 30);
indexbackground.setBounds(0,0,500, 450);
pan.add(indexbackground);
pan.add(s_no);
pan.add(tf_no);
pan.add(s_name);
pan.add(tf_name);
pan.add(s_type);
pan.add(tf_type);
pan.add(btn_add);
pan.setOpaque(false);
pan.setLayout(null);
this.getLayeredPane().add(indexbackground,new Integer(Integer.MIN_VALUE));
this.setContentPane(pan);
btn_add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=pfs;user=sa;password=xiaoguang");
Statement stmt = conn.createStatement();
ResultSet rs=stmt.executeQuery(" select * from subject where subjectNo='"+tf_no.getText().trim()+"' and userno='"+Login.tf_userno.getText().trim()+"'");
if(rs.next()) {
rs=stmt.executeQuery("update subject set subjectNo='"+tf_no.getText().trim()+"',subjectName='"+tf_name.getText().trim()+"',subjectType='"+tf_type.getText().trim()+"' ,userno='"+Login.tf_userno.getText().trim()+"'where subjectNo='"+tf_no.getText().trim()+"'");
JOptionPane.showMessageDialog(null,"修改成功");
return;
}
else{
JOptionPane.showMessageDialog(null,"修改失败");
}
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, e1.getMessage());
}
}
});
}
} 展开
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
public class subjectupdate extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
JLabel s_no = new JLabel("科目编号");
JTextField tf_no = new JTextField();
JLabel s_name = new JLabel("科目名");
JTextField tf_name = new JTextField();
JLabel s_type = new JLabel("科目类型");
JTextField tf_type = new JTextField();
JButton btn_add = new JButton("修改");
JPanel pan = new JPanel();
ImageIcon image=new ImageIcon("images/subjectimage.jpg");
JLabel indexbackground=new JLabel(image);
subjectupdate() {
this.setBounds(100, 100, 500, 450);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLayout(null);
s_no.setBounds(100, 50, 70, 30);
tf_no.setBounds(200, 50, 100, 30);
s_name.setBounds(100, 100, 70, 30);
tf_name.setBounds(200, 100, 100, 30);
s_type.setBounds(100, 150, 70, 30);
tf_type.setBounds(200, 150, 100, 30);
btn_add.setBounds(200, 200, 100, 30);
indexbackground.setBounds(0,0,500, 450);
pan.add(indexbackground);
pan.add(s_no);
pan.add(tf_no);
pan.add(s_name);
pan.add(tf_name);
pan.add(s_type);
pan.add(tf_type);
pan.add(btn_add);
pan.setOpaque(false);
pan.setLayout(null);
this.getLayeredPane().add(indexbackground,new Integer(Integer.MIN_VALUE));
this.setContentPane(pan);
btn_add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=pfs;user=sa;password=xiaoguang");
Statement stmt = conn.createStatement();
ResultSet rs=stmt.executeQuery(" select * from subject where subjectNo='"+tf_no.getText().trim()+"' and userno='"+Login.tf_userno.getText().trim()+"'");
if(rs.next()) {
rs=stmt.executeQuery("update subject set subjectNo='"+tf_no.getText().trim()+"',subjectName='"+tf_name.getText().trim()+"',subjectType='"+tf_type.getText().trim()+"' ,userno='"+Login.tf_userno.getText().trim()+"'where subjectNo='"+tf_no.getText().trim()+"'");
JOptionPane.showMessageDialog(null,"修改成功");
return;
}
else{
JOptionPane.showMessageDialog(null,"修改失败");
}
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, e1.getMessage());
}
}
});
}
} 展开
2个回答
展开全部
rs=stmt.executeQuery("update subject set subjectNo='"+tf_no.getText().trim()+"',subjectName='"+tf_name.getText().trim()+"',subjectType='"+tf_type.getText().trim()+"' ,userno='"+Login.tf_userno.getText().trim()+"'where subjectNo='"+tf_no.getText().trim()+"'");
这个有问题
用stmt.executeUpdate("update subject set subjectNo='"+tf_no.getText().trim()+"',subjectName='"+tf_name.getText().trim()+"',subjectType='"+tf_type.getText().trim()+"' ,userno='"+Login.tf_userno.getText().trim()+"'where subjectNo='"+tf_no.getText().trim()+"'");
这个有问题
用stmt.executeUpdate("update subject set subjectNo='"+tf_no.getText().trim()+"',subjectName='"+tf_name.getText().trim()+"',subjectType='"+tf_type.getText().trim()+"' ,userno='"+Login.tf_userno.getText().trim()+"'where subjectNo='"+tf_no.getText().trim()+"'");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询