如何使用dataSource操作数据库进行CRUD操作
@Resource
private DataSource dataSource;
try {
dbConnection = dataSource.getConnection();
PreparedStatement ps = dbConnection.prepareStatement(entity.getSql());
String trimmedSql = entity.getSql().trim().toLowerCase();
if(!(trimmedSql.startsWith("insert") || trimmedSql.startsWith("update"))) {
return "fail";
}
ps.execute();
}catch (Exception e) {
return "fail";
}finally {
try{
if(Objects.nonNull(dbConnection)) {
dbConnection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}