如何修改数据库表中的某一个字段的值呢?
请教一下,如何修改表中某一字段的值呀,请大家帮帮忙,谢谢了!
----------------解决方案--------------------------------------------------------
UPDATE 表名 set 字段='你要改的值' where 字段=''
----------------解决方案--------------------------------------------------------
我已经试过了,那样改不了.不过还是要谢谢你
----------------解决方案--------------------------------------------------------
2楼的语句怎么会改不了呢?
是不是你设了什么约束条件?
----------------解决方案--------------------------------------------------------
我是不是没说清楚,我再说一次吧,我要放的值不是一个固定的值,就是我做了一个还书的系统,每还一本后要在图书馆里加上一本,还要在自己的卡上把那个字段修改了,同时修改两个我就不知道怎么写了,把卡上那个改了,我已经实现了.可是图书馆里怎么也加不上一本.
----------------解决方案--------------------------------------------------------
用触发器来实现。
----------------解决方案--------------------------------------------------------
[CODE]
/*******图书信息窗体监听事件*******/
class huan_actionPerformed implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
String str="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=tushuguanli.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection(str);
Statement stmt=conn.createStatement();
if(e.getSource()==bhuan)
{
JOptionPane.showMessageDialog(null,"你要还的书已经提交到数据库,谢谢阅读!","提示",JOptionPane.WARNING_MESSAGE);
/*****先删除原先存在的学号****/
stmt.executeUpdate("delete * from memory where 卡号 = '"+txtnum.getText()+"' and 书名='"+txtbook.getText()+"'");
/***********更新数据并存入到数据库*******/
stmt.executeUpdate("insert into memory values ('"+tnum.getText()+"','"+tbook.getText()+"','"+tautor.getText()+"','"+tchu.getText()+"','已还')");
/*try
{
String str1="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=tushuguanli.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(str1);
Statement stmt1=con.createStatement();
ResultSet rs1=stmt1.executeQuery("select * from book where 书名='"+txtbook.getText()+"'");
jtno.setText(rs1.getString("书号"));
jtname.setText(rs1.getString("书名"));
String type=rs1.getString("类别");
jctype.setSelectedItem(type);
jtautor.setText(rs1.getString("作者"));
jtchu.setText(rs1.getString("出版社"));
jtcount.setText(rs1.getString("数量"));
int count=Integer.parseInt(jtcount.getText());
count++;
jtcount.setText(String.valueOf(count));
stmt1.executeUpdate("delete * from book where 书名='"+txtbook.getText()+"'");
stmt1.executeUpdate("insert into book values('"+jtno.getText()+"','"+tbook.getText()+"','"+jctype.getSelectedItem()+"','"+tautor.getText()+"','"+tchu.getText()+"','"+jtcount.getText()+"')");
}
catch(Exception ee)
{
ee.printStackTrace();
}*/
}
if(e.getSource()==breturn)
{
/***显示还书界面***/
labnum.setVisible(true);
txtnum.setVisible(true);
labbook.setVisible(true);
txtbook.setVisible(true);
buthuan.setVisible(true);
/***隐藏图书信息***/
lnum.setVisible(false);
tnum.setVisible(false);
lbook.setVisible(false);
tbook.setVisible(false);
lautor.setVisible(false);
tautor.setVisible(false);
lchu.setVisible(false);
tchu.setVisible(false);
bhuan.setVisible(false);
breturn.setVisible(false);
}
}
catch(Exception ee)
{
ee.printStackTrace();
}
}
}
这是其中的一部分代码,总提示说:无效的游标状态,我也不知道是怎么回事.
[/CODE]
----------------解决方案--------------------------------------------------------
我已经修改正确了,谢谢大家的帮助
----------------解决方案--------------------------------------------------------
楼主,你是怎么解决的呀?
----------------解决方案--------------------------------------------------------
好吧
----------------解决方案--------------------------------------------------------