Guest User

Untitled

a guest
Jun 13th, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. package Basededatos;
  2.  
  3. import Vista.MantenedorFuncionarios;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.SQLException;
  8. import java.util.*;
  9. import java.sql.ResultSet;
  10. import javax.swing.JOptionPane;
  11. import Vista.MantenedorFuncionarios;
  12. import java.util.logging.Level;
  13. import java.util.logging.Logger;
  14.  
  15.  
  16.  
  17. public class FuncionariosDB {
  18.  
  19.  
  20. public void agregarFun(){
  21. MantenedorFuncionarios frame = new MantenedorFuncionarios();
  22.  
  23. try{
  24. Connection con=null;
  25. Class.forName("com.mysql.jdbc.Driver");
  26. con = DriverManager.getConnection("jdbc:mysql://localhost/empresa","root","");
  27. PreparedStatement st=con.prepareStatement("INSERT INTO funcionariobd(rut, nombre, fechaNacimiento, cargo, sueldo) VALUES (?,?,?,?,?)");
  28. st.setString(1, frame.getRut());
  29. st.setString(2, frame.getNom());
  30. st.setString(3, frame.getFecNac());
  31. st.setString(4, frame.getCargo());
  32. st.setString(5, frame.getSueldo());
  33.  
  34. st.executeUpdate();
  35. st.close();
  36.  
  37. JOptionPane.showMessageDialog(null,"Usuario Agregado");
  38. } catch (SQLException ex) {
  39. Logger.getLogger(MantenedorFuncionarios.class.getName()).log(Level.SEVERE, null, ex);
  40. } catch (ClassNotFoundException ex) {
  41. Logger.getLogger(FuncionariosDB.class.getName()).log(Level.SEVERE, null, ex);
  42. }
  43.  
  44. }
  45.  
  46.  
  47.  
  48.  
  49. }
Add Comment
Please, Sign In to add comment