Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Haosvit/e9b378121f917556ab9526f5bfd7d18b to your computer and use it in GitHub Desktop.
Save Haosvit/e9b378121f917556ab9526f5bfd7d18b to your computer and use it in GitHub Desktop.
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