I wish to create login page which uses Email Address and Password as log in details. Is there anyway to do this using Jackcess? I am avoiding ucanaccess method because it keeps giving me SQL exception error.
Here's the code for sign in page:
login.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent action){
try {
File file= new File("User_Details.accdb");
Database data=DatabaseBuilder.open(file);
if((file.exists())&&(!file.isDirectory())){
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
Here's the database:
public void actionPerformed(ActionEvent action) {
if(action.getSource()==next){
int x=0;
String s1=t_name.getText();
String s2=t_email.getText();
char[]s3=pw.getPassword();
char[]s4=c_pw.getPassword();
String pass=new String(s3);
String conf=new String(s4);
String s5=t_phone.getText();
Object s6=city.getSelectedItem();
String s7=t_cc.getText();
if((!s1.isEmpty())&&(!s2.isEmpty())&&(!pass.isEmpty())&&(!conf.isEmpty())&&(!s5.isEmpty())&&(!s7.isEmpty())&&(pass.equals(conf))){
String file="C:/Users/Ameer Izwan/Documents/User_Details.accdb";
try{
Database db=DatabaseBuilder.create(Database.FileFormat.V2000,new File(file));
Table table=new TableBuilder("Login")
.addColumn(new ColumnBuilder("Email Address",DataType.TEXT))
.addColumn(new ColumnBuilder("Name",DataType.TEXT))
.addColumn(new ColumnBuilder("Password",DataType.TEXT))
.addColumn(new ColumnBuilder("Phone No",DataType.TEXT))
.addColumn(new ColumnBuilder("Cities",DataType.TEXT))
.addColumn(new ColumnBuilder("Credit/Debit Card No",DataType.TEXT))
.toTable(db);
table.addRow(s2,s1,pass,s5,s6,s7);
x++;
if(x>0){
for(int i=0;i<=100;i++){
final int value=i;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
bar.setValue(value);
}
});
This is the database after created and filled: https://i.sstatic.net/2UUh8.png
This is the sample input and output: https://i.sstatic.net/HMjzc.png
Do you guys have any idea using Jackcess for this?
From http://jackcess.sourceforge.net/ sample code, I managed to write a code that would work for you.
public boolean authenticate(String email, char[] password) {
Table table = DatabaseBuilder.open(new File("C:/Users/Ameer Izwan/Documents/User_Details.accdb")).getTable("Login");
Row row = CursorBuilder.findRow(table,
Collections.singletonMap("Email Address", email));
if(row != null) {
String p = row.get('Password');
// if the password matches authenticate or else deny
} else {
// Dont authenticate
}
}
NOTE: Make sure the file path is absolute or else row will return null