public long insert(String sql, Object... args) {
long id = 0;
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try{
connection = ConnectionContext.getInstance().get();
//connection=JDBCUtils.getConnection();
preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
if(args != null){
for(int i = 0; i < args.length; i++){
preparedStatement.setObject(i + 1, args[i]);
}
}
preparedStatement.executeUpdate();
resultSet=preparedStatement.getGeneratedKeys();
if(resultSet.next()){
id=resultSet.getLong(1);
}
}catch(Exception e)
{
e.printStackTrace();
}finally{
JDBCUtils.release(resultSet,preparedStatement);
}
return id;
}