java sql 修改_JAVA中修改SQL报错

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楼。还是错的, 界面要跳转了`但是数据不更新了

神小忘我也是这么分析的,那该怎么做啊

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值