Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- btnInsertarReg_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- int empNo = Integer.parseInt(empno.getText());
- float Salario = Float.parseFloat(salario.getText());
- int Comision = Integer.parseInt(comision.getText());
- String fecha = fechaalt.getText().toString();
- DateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
- formato.setLenient(true);
- Date mifecha = (Date) formato.parse(fecha);
- java.sql.Date sqlDate1 = new java.sql.Date(mifecha.getTime());
- int Dept_no = Integer.parseInt(comboDep.getSelectedItem().toString());
- int Dir = Integer.parseInt(comboDirec.getSelectedItem().toString());
- String mensaje2=OperacionesEmple.insertaremple(conexion, empNo, apellido.getText(),
- oficio.getText(), Salario, Comision,
- sqlDate1, Dept_no, Dir);
- textArea_1.setText(mensaje2);
- }catch(NumberFormatException a){
- textArea_1.setText("ERROR EL DATO TIENE QUE SER NUMÉRICO");
- }catch(ParseException e3) {
- textArea_1.setText("LA FECHA NO ES VALIDA");
- }
- }
- });
- JComboBox comboDirec = new JComboBox();
- String consulta2="select count(*) from empleados";
- Statement sentencia2;
- try {
- sentencia2 = conexion.createStatement();
- ResultSet resul2;
- resul2 = sentencia2.executeQuery(consulta2);
- resul2.next();
- int filas = resul2.getInt(1);
- resul2.close();
- String sql = "select emp_no from empleados";
- Statement sentencia = conexion.createStatement();
- ResultSet res = sentencia.executeQuery(sql);
- String[] dir = new String[filas];
- int i = 0;
- if (res.next())
- {
- do {
- dir[i]=res.getString(1);
- i++;
- }while (res.next());
- }
- else {
- textArea.append(" NO HAY DIRECTORES ");
- }
- comboDirec.setModel(new DefaultComboBoxModel(dir));
- } catch (SQLException e3) {
- // TODO Auto-generated catch block
- e3.printStackTrace();
- }
- comboDirec.setBounds(163, 91, 122, 20);
- panelempleados.add(comboDirec);
- JComboBox comboDep = new JComboBox();
- String consulta3="select count(*) from DEPARTAMENTOS";
- Statement sentencia3;
- try {
- sentencia3 = conexion.createStatement();
- ResultSet resul3;
- resul3 = sentencia3.executeQuery(consulta3);
- resul3.next();
- int filas = resul3.getInt(1);
- resul3.close();
- String sql = "select dept_no from departamentos";
- Statement sentencia = conexion.createStatement();
- ResultSet res = sentencia.executeQuery(sql);
- String[] dir = new String[filas];
- int i = 0;
- if (res.next())
- {
- do {
- dir[i]=res.getString(1);
- i++;
- }while (res.next());
- }
- else {
- textArea.append(" NO HAY DEPARTAMENTOS ");
- }
- comboDep.setModel(new DefaultComboBoxModel(dir));
- } catch (SQLException e3) {
- // TODO Auto-generated catch block
- e3.printStackTrace();
- }
- comboDep.setBounds(491, 94, 111, 20);
- panelempleados.add(comboDep);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement