Tutorial by Examples

This is the simplest way to connect. First, the driver has to be registered with java.sql.DriverManager so that it knows which class to use. This is done by loading the driver class, typically with java.lang.Class.forname(<driver class name>). /** * Connect to a PostgreSQL database. *...
Instead of specifying connection parameters like user and password (see a complete list here) in the URL or a separate parameters, you can pack them into a java.util.Properties object: /** * Connect to a PostgreSQL database. * @param url the JDBC URL to connect to. Must start with "jdbc:...
It is common to use javax.sql.DataSource with JNDI in application server containers, where you register a data source under a name and look it up whenever you need a connection. This is code that demonstrates how data sources work: /** * Create a data source with connection pool for PostgreSQL c...

Page 1 of 1