Well, the answer to this question could fill books ;-).
Do you want to execute a query, return a ResultSet and loop over the reader yourself? In this case, it is probably the best approach NOT to manage the database connection yourself, but to use the injection feature of JavaEE.
Or do you want to write the result of the query to a Java class?
Both links mention an interface "EntityManager", wich is used to perform your database access.
This "EntityManager" is configured through a file "persistence.xml" in your deployment. And "persistence.xml" points to a datasource configured in the WildFly file "standalone.xml" - the first link contains also a datasource configuration snippet for this file.
Best regards
Wolfgang