Ola pessoal…
estou tentando persistir um objeto do tipo Date utilizando reflexão,
mas o compilador rotorna um erro de sintaxe, exception java.sql.SQLSyntaxErrorException-Syntax
malditas linhas vermelhas que aparecem no meu console…iuehiuehie
eis o código que estou usando, se alguém puder me ajudar agradeço, pois jah bati bastante a kbeça tentndo resolver
vlwwww
public void insere(Object objeto) throws BDExceptions {
StringBuilder sbInsert = new StringBuilder();
StringBuilder sbValues = new StringBuilder();
try{
sbInsert.append("insert into " + objeto.getClass().getSimpleName() + "(");
for(Field f : objeto.getClass().getDeclaredFields()){
if(!f.getName().equalsIgnoreCase("id")){
f.setAccessible(true);
sbInsert.append(f.getName() + ",");
if(f.getType().toString().endsWith("String"))
sbValues.append("'" + f.get(objeto) + "',");
else
sbValues.append(f.get(objeto) + ",");
}
}
sbInsert.replace(sbInsert.lastIndexOf(","), sbInsert.length(), ") values(");
sbValues.replace(sbValues.lastIndexOf(","), sbValues.length(), ")");
sbInsert.append(sbValues);
System.out.println("SQL: " + sbInsert.toString());
Statement s = this.conexao.createStatement();
s.execute(sbInsert.toString());
}catch (SQLException e){
throw new BDExceptions(e.getClass().getName() + "-" + e.getMessage());
}catch (IllegalArgumentException e) {
throw new BDExceptions(e.getClass().getName() + "-" + e.getMessage());
}catch (IllegalAccessException e) {
throw new BDExceptions(e.getClass().getName() + "-" + e.getMessage());
}
}