Last active
May 8, 2023 13:43
-
-
Save jeffersonchaves/482d67e7807e076a87a40b28900fd23e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SellerRepository { | |
private Connection conn; | |
private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); | |
public SellerRepository(){ | |
ConnectionFactory connectionFactory = new ConnectionFactory(); | |
conn = connectionFactory.getConnection(); | |
} | |
public void insert(){ | |
PreparedStatement statement = null; | |
ResultSet resultSet = null; | |
try { | |
statement = conn.prepareStatement("INSERT INTO seller (Name, Email, BirthDate, BaseSalary, DepartmentId) VALUES (?, ?, ?, ?, ?)"); | |
statement.setString(1, "Jeff Cyan"); | |
statement.setString(2, "[email protected]"); | |
statement.setDate(3, new java.sql.Date(sdf.parse("22/04/1985").getTime())); | |
statement.setDouble(4, 1500.0); | |
statement.setInt(5, 4); | |
int rowsAffected = statement.executeUpdate(); | |
System.out.println("Done! " + rowsAffected + " row(s) affected."); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment