I want to write a function that will execute different queries. I want it to pass the table name and the method of select, insert, and a list of values with regard to where the like. I've done something similar in php and I handled everything in the array, but do not know how to solve in Java, there maybe some ready class?
My current solution in PHP:
$user = db::getInstance()->update('users', 2, array(
'password' => 'newpassword'));
public function update($table, $id, $fields){
$set = '';
$x = 1;
foreach($fields as $name => $value){
$set .= "{$name} = ?";
if($x < count($fields)){
$set .= ', ';
}
}
$sql = "UPDATE {$table} SET {$set} where id = {$id}";
if(!$this->query($sql, $fields)->error()){
return true;
}
}