import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class pinxiugai implements ActionListener
{
private String str02;
private String str2;
private String sql2;
private int indexID;
Frame f2=new Frame("品种修改");
Choice ch2=new Choice();
TextField tf2=new TextField("");
Button bt2=new Button("修改");
Button btt2=new Button("返回首页");
private Connection connect=null;//数据库连接对象
private Statement st=null;//数据库命令对象
private ResultSet rset=null;//记录集对象
public pinxiugai()
{
f2.setLayout(null);
f2.add(ch2);
f2.add(tf2);
f2.add(bt2);
f2.add(btt2);
ch2.setBounds(20,50,100,20);
tf2.setBounds(20,80,100,20);
bt2.setBounds(125,80,50,20);
btt2.setBounds(60,120,70,20);
bt2.addActionListener(this);
btt2.addActionListener(this);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//系统加载数据命令
}
catch(ClassNotFoundException ce)
{
System.out.println(ce);
}
try
{
connect = DriverManager.getConnection("jdbc:odbc:cx");//执行括号中的连接字符串
st = connect.createStatement();//创建命令对象
rset= st.executeQuery("Select * From cx Order By ID DESC");
while(rset.next())
{
str02=rset.getString("Name");
ch2.add(str02);
}
}
catch(SQLException se)
{
System.out.println(se);
}
f2.setSize(200,150);
f2.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==bt2)//这里是修改的按钮
{
//rset= st.executeQuery("Select * From cx Order By ID DESC");
ch2.removeAll();
str2=tf2.getText();
sql2="Select * From cx Where Name='"+str2+"'";
try
{
rset= st.executeQuery(sql2);
rset.next();
indexID=Integer.parseInt(rset.getString("ID"));
}
catch(SQLException se)
{
System.out.println(se);
}
}
else if(ae.getSource()==btt2)
{
f2.dispose();
}
}
}
这是我写的一段测试用的小程序,红色部分的代码该怎么写,才能达到修改数据库内容的效果呢~
我用的是ACCESS的数据库谢谢