⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 add.java

📁 自己编写的一个程序
💻 JAVA
字号:
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.*;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.event.*;

public class Add extends JFrame  implements ActionListener{

	private JComboBox comboBox;
	private JTextField textField_3;
	private JTextField textField_2;
	private JTextField textField;
	public JLabel beijing=new JLabel();
	public JButton cancelbtn=new JButton("取消");	
	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			Add frame = new Add();
			frame.setVisible(true);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the frame
	 */
	 
	 public void actionPerformed(ActionEvent e)
	 {
	 	if(e.getSource()==cancelbtn)
	 	{
	 		this.setVisible(false);
	 		this.dispose();
	 		}
	 	}
	public Add()throws SQLException {
		super();
		getContentPane().setLayout(null);
		setBounds(100, 100, 500, 375);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		final JLabel label = new JLabel();
		label.setText("姓名");
		label.setBounds(107, 59, 60, 15);
		getContentPane().add(label);

		final JLabel label_1 = new JLabel();
		label_1.setText("性别");
		label_1.setBounds(107, 98, 60, 15);
		getContentPane().add(label_1);

		final JLabel label_2 = new JLabel();
		label_2.setText("工资");
		label_2.setBounds(107, 174, 60, 15);
		getContentPane().add(label_2);

		final JLabel label_3 = new JLabel();
		label_3.setText("年龄");
		label_3.setBounds(107, 133, 60, 15);
		getContentPane().add(label_3);

		final JLabel label_4 = new JLabel();
		label_4.setText("添加");
		label_4.setBounds(165, 25, 96, 24);
		getContentPane().add(label_4);

		textField = new JTextField();
		textField.setText("");
		textField.setBounds(244, 59, 95, 20);
		getContentPane().add(textField);

		textField_2 = new JTextField();
		textField_2.setText("");
		textField_2.setBounds(244, 133, 95, 20);
		getContentPane().add(textField_2);

		textField_3 = new JTextField();
		textField_3.setText("");
		textField_3.setBounds(244, 174, 95, 20);
		getContentPane().add(textField_3);
		
		cancelbtn.addActionListener(this);
		cancelbtn.setBounds(270, 240, 99, 23);
		this.getContentPane().add(cancelbtn);
		//beijing=new JLabel(
		beijing.setIcon(new ImageIcon("flash1.gif"));
		this.getContentPane().add(beijing);
		beijing.setBounds(0,40,120,180);

		final JButton button = new JButton();
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				try{
					//加载JDBC-ODBC桥驱动程序
					Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				}
				catch(ClassNotFoundException ex){
					//text.setText(ex.getMessage());
					System.exit(-1);
				}
				try{
					
					String URL="jdbc:odbc:职工工资信息";
					Connection con=DriverManager.getConnection(URL);
					Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
					String s=textField.getText();
					String s1=comboBox.getSelectedItem().toString();
					String s2=textField_2.getText();
					String s3=textField_3.getText();
					System.out.print(s+s1+s2+s3);
					String SQL="insert into 职工工资信息(姓名,性别,年龄,工资)"+"values('"+s+"','"+s1+"','"+s2+"','"+s3+"')";
					int rowCount=stmt.executeUpdate(SQL);
					stmt.close();
					con.close();
					
					
					
			}
				catch(SQLException ex)
				{
					ex.printStackTrace();
			
				}
				setVisible(false);
		}});
		button.setText("提交");
		button.setBounds(162, 240, 99, 23);
		getContentPane().add(button);

		comboBox = new JComboBox();
		comboBox.addItem("男");
		comboBox.addItem("女");
		
		comboBox.setBounds(244, 94, 95, 24);
		getContentPane().add(comboBox);
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -