Created
April 23, 2016 14:38
-
-
Save Haosvit/e9b378121f917556ab9526f5bfd7d18b to your computer and use it in GitHub Desktop.
This file contains 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
1. Definnig a SimpleDateFormat | |
2. Using that SimpleDateFormat to format date typeof java.util.Date | |
3. Using # instead of ' to seperate date string to insert into MS Access | |
EXAMPLE: | |
public boolean addCustomer(Customer cus) { | |
SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd"); | |
String insertDob = df.format(cus.getDob()); | |
String queryStr = "insert into KHACHHANG (MaKhachHang, TenKhachHang, NgaySinh, GioiTinh, Email, SDT) " | |
+ "values ('" + cus.getId() + "', '" + cus.getFullName() | |
+ "', #" + insertDob + "#, " | |
+ cus.isMale() + ", '" + cus.getEmail() | |
+ "', '" + cus.getPhoneNumber() + "');"; | |
try { | |
update(queryStr); | |
} | |
catch (SQLException e) { | |
e.printStackTrace(); | |
return false; | |
} | |
return true; | |
} | |
// Customer class snipet | |
public class Customer { | |
private String id; | |
private String fullName; | |
private Date dob; | |
private boolean isMale; | |
private String email; | |
private String phoneNumber; | |
// more | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment