import java.sql.SQLException; import java.sql.Connection; import java.sql.Date; import java.sql.PreparedStatement; import java.sql.DriverManager; import java.time.LocalDate; class Program01 { public static void insertEmployee(Employee employee) { Connection conn = null; try { String url = "jdbc:mysql://localhost:3306/surubt"; conn = DriverManager.getConnection(url, "surubt", "titok"); String sql = "insert into employees" + " (name, city, salary, birth) values" + " (?, ?, ?, ?)"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, employee.name); pstmt.setString(2, employee.city); pstmt.setDouble(3, employee.salary); pstmt.setDate(4, Date.valueOf(employee.birth)); pstmt.execute(); }catch(SQLException ex) { System.err.println("Hiba! Az SQL művelet sikertelen!"); System.err.println(ex.getMessage()); } } public static void main(String[] args) { Employee emp = new Employee( 1, "Csendes Emese", "Szolnok", 345, LocalDate.parse("2002-05-15") ); insertEmployee(emp); } }