Typically the DataSource
implementation you get from a Java EE container will be a thread-safe object backed by a connection pool, and thread-safety (or otherwise) of the underlying JDBC connections is not really relevant. The usual pattern when you need to talk to the database is to call getConnection()
on the data source to obtain a connection object, make the necessary database calls and then close()
the connection. Under the covers this won't actually close the underlying connection, but simply return it to the connection pool for future use. Any individual connection will only be used by one thread at a time.
This is the idiom used by things like the Spring JdbcTemplate
.