热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

java增删改查代码_增删改查java代码库云代码

[java]代码库packagewww.baidu.com;importjava.awt.Frame;importjava.awt.GridLayout;importjava.aw

[java]代码库package www.baidu.com;

import java.awt.Frame;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import javax.swing.JButton;

import javax.swing.JDialog;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

public class revise extends JDialog implements ActionListener {

private JTextField setName,setNumber,setSex,setAge,setPost,setWage,setJop;

private JLabel name,number,age,sex,wage,post,jop;

private JButton Addyes,Addno;

private Connection con=null;

private Statement sql=null;

private ResultSet rs=null;

private String SQLname,SQLsex,SQLpost,SQLjop;

private int SQLnumber,SQLage,SQLwage;

//chaxun xx;

revise(Frame fck,String ckm,Boolean msck,chaxun xx,int j){

super(fck, ckm,msck);

if(j==-1){

JOptionPane.showMessageDialog(null,"请选中要修改的行");

return;

}

//xx=new chaxun();

setNumber=new JTextField(5);

setNumber.setText((String)xx.getValueAt(j,0).toString());

setNumber.setEditable(false);//设置为不能修改,防止出错

setName=new JTextField(5);

setName.setText((String)xx.getValueAt(j,1));

setAge=new JTextField(5);

setAge.setText((String)xx.getValueAt(j,3).toString());

setSex=new JTextField(5);

setSex.setText((String)xx.getValueAt(j,2));

setPost=new JTextField(5);

setPost.setText((String)xx.getValueAt(j,4));

setWage=new JTextField(5);

setWage.setText((String)xx.getValueAt(j,5).toString());

setJop=new JTextField(5);

setJop.setText((String)xx.getValueAt(j,6));

name=new JLabel("姓名");

number=new JLabel("学号");

age=new JLabel("年龄");

sex=new JLabel("性别");

post=new JLabel("职位");

wage=new JLabel("工资");

jop=new JLabel("地点");

Addyes=new JButton("确定");

Addno=new JButton("取消");

this.add(number);this.add(setNumber);

this.add(name);this.add(setName);

this.add(sex);this.add(setSex);

this.add(age);this.add(setAge);

this.add(post);this.add(setPost);

this.add(wage);this.add(setWage);

this.add(jop);this.add(setJop);

this.add(Addyes); this.add(Addno);

this.Addyes.addActionListener(this);

this.Addno.addActionListener(this);

this.setSize(350,400);

this.setLocation(100, 260);

this.setLayout(new GridLayout(8,2));

this.setVisible(true);

this.setResizable(false);

}

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

if(e.getSource()==Addyes){

try{

// 获得连接

Class.forName("com.mysql.jdbc.Driver");

con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/nature","root","root");

// 建立查询条件

String recode = " update nature set name=?,sex=?,age=?,post=?,wage=?,jop=? where number=?";

PreparedStatement input=con.prepareStatement(recode);

SQLnumber=Integer.parseInt(setNumber.getText());

SQLage= Integer.parseInt(setAge.getText());

SQLwage= Integer.parseInt(setWage.getText());

// input.setInt(1, SQLnumber);

input.setString(1, setName.getText());

input.setString(2,setSex.getText());

input.setInt(3,SQLage);

input.setString(4,setPost.getText());

input.setInt(5,SQLwage);

input.setString(6,setJop.getText());

input.setInt(7, SQLnumber); //修改的条件

input.executeUpdate();

JOptionPane.showMessageDialog(null, "修改成功");

this.dispose();

}

catch(NumberFormatException nu){

JOptionPane.showMessageDialog(null,"你还没有输入哦","错误",JOptionPane.ERROR_MESSAGE);

}

catch(ClassNotFoundException cnfe){

JOptionPane.showMessageDialog(null,"数据源错误","错误",JOptionPane.ERROR_MESSAGE);

}

catch(SQLException sqle){

sqle.printStackTrace();

JOptionPane.showMessageDialog(null,"数据操作错误","错误",JOptionPane.ERROR_MESSAGE);

}

finally

{

try {

if(rs!=null)

{

rs.close();

}

if(sql!=null)

{

sql.close();

}

if(con!=null)

{

con.close();

}

} catch (Exception e1){}

}

}

if(e.getSource()==Addno){

this.dispose();

}

}

}

[源代码打包下载]

7ab7b94785bbdb79d4aaa6009386543f.gif增删改查.zip(50积分)[5 次下载]

694748ed64b9390909c0d88230893790.png



推荐阅读
author-avatar
狂龙
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有