爱问知识人 爱问教育 医院库

如何使用JavaSwing界面实现数据库基本操作?

首页

如何使用JavaSwing界面实现数据库基本操作?

如何使用JavaSwing界面实现数据库基本操作?

提交回答

全部答案

    2017-07-27 00:05:26
  •   用Java Swing图形化界面来对数据库操作(增,删,查,改) 数据库版本:SQLServer2000 数据库名:dxaw 用户名:dxaw 密码:123 表名:bankAccount 表结构:id(int[自动增长]),ownerName(varchar),accountValue(varchar),accountLevel(varchar) 程序代码:
    import java。
      awt。event。ActionEvent; import java。awt。event。ActionListener; import java。sql。*; import java。awt。*; import javax。swing。*; public class data extends JFrame implements ActionListener{ JButton add,select,del,update; JTable table; Object body[][]=new Object[50][4]; String title[]={"编号","姓名","分数","级别"}; Connection conn; Statement stat; ResultSet rs; JTabbedPane tp; public data() { super("数据库操作"); this。
      setSize(400,300); this。setLocation(300,200); this。setDefaultCloseOperation(JFrame。EXIT_ON_CLOSE); JPanel ps=new JPanel(); add=new JButton("添加"); select=new JButton("显示"); update=new JButton("更改"); del=new JButton("删除"); add。
      addActionListener(this); select。addActionListener(this); update。addActionListener(this); del。addActionListener(this); ps。
      add(add);ps。add(select);ps。add(update);ps。add(del); table=new JTable(body,title); tp=new JTabbedPane(); tp。add("bankAccount表",new JScrollPane(table)); this。
      getContentPane()。add(tp,"Center"); this。getContentPane()。add(ps,"South"); this。setVisible(true); this。connection(); } public void connection(){ try { Class。
      forName("com。microsoft。jdbc。sqlserver。SQLServerDriver"); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=dxaw"; conn=DriverManager。
      getConnection(url,"dxaw","123"); stat = conn。createStatement(ResultSet。TYPE_SCROLL_INSENSITIVE, ResultSet。CONCUR_READ_ONLY); } catch (Exception ex) { } } public static void main(String[] args) { data data = new data(); } public void actionPerformed(ActionEvent e) { if(e。
      getSource()==add) {add();} if(e。getSource()==select) {select();} if(e。getSource()==update) {update();} if(e。getSource()==del) {del();} } public void del() { try { int row=table。
      getSelectedRow(); stat。executeUpdate("delete bankAccount where accountID='"+body[row][0]+"'"); JOptionPane。showMessageDialog(null,"数据已成功删除"); this。
      select(); } catch (SQLException ex) { } } public void update() { try { int row=table。getSelectedRow(); JTextField t[]=new JTextField[6]; t[0]=new JTextField("输入姓名:"); t[0]。
      setEditable(false); t[1]=new JTextField(); t[2]=new JTextField("输入分数:"); t[2]。setEditable(false); t[3]=new JTextField(); t[4]=new JTextField("输入级别:"); t[4]。
      setEditable(false); t[5]=new JTextField(); String but[]={"确定。

    王***

    2017-07-27 00:05:26

类似问题

换一换

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):