importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjava.sql.Connection...
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Qukuan extends JFrame {
public Qukuan() {
super();
getContentPane().setLayout(null);
setBounds(100, 100, 500, 375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JLabel label = new JLabel();
label.setText("取款界面");
label.setBounds(10, 0, 65, 18);
getContentPane().add(label);
final JLabel label_1 = new JLabel();
label_1.setText("请输入您要提取的金额:(单次最高面额为5000元)");
label_1.setBounds(10, 51, 299, 18);
getContentPane().add(label_1);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent age) {
String Driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
try {
Class.forName(Driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
String user = "sa";
String password = "9905368";
String url = "jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=atm";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
con = java.sql.DriverManager.getConnection(url, user, password);
stmt = con.createStatement();
stmt.executeQuery("update u_user set u_money=(u_money-100) where u_name='kobe'");
while (rs.next()) {
Qukuan b=new Qukuan();
Qukuanwan a=new Qukuanwan();
b.setVisible(false);
a.setVisible(true);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
rs.close();
} catch (SQLException e) {
}
try {
stmt.close();
} catch (SQLException e) {
}
try {
con.close();
} catch (SQLException e) {
}
}
}
});
运行后SQL里面数据被修改但是报错java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]No ResultSet set was produced.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQuery(Unknown Source)
at Qukuan$1.actionPerformed(Qukuan.java:68)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
…………
回答一楼,加了 rs=一样报错。
如果我把rs=stmt.executeQuery("update u_user set u_money=(u_money-100) where u_name='kobe'");
改成rs = stmt.executeQuery("select * from u_user"); 就没问题
回答3楼。还是错的, 界面要跳转了`但是数据不更新了
神小忘我也是这么分析的,那该怎么做啊
展开