Advertisement
Guest User

Untitled

a guest
Dec 4th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public void añadirDatosSQL() {
  2.  
  3. for(Empleado e : empleados)
  4. {
  5. try
  6. {
  7. Class.forName("com.mysql.jdbc.Driver");
  8. Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost/empleados", "usuario","123456");
  9. Statement sentencia = conexion.createStatement();
  10. boolean resul = sentencia.execute("INSERT INTO empleado VALUES("+ e.getId() + e.getNombre() + e.getApell1() + e.getApell2() + e.getSalario() + ")");
  11.  
  12. }
  13. catch(ClassNotFoundException | SQLException err)
  14. {
  15. System.out.println("Error al conectar a la base de datos");
  16. }
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement