September 2018
Intermediate to advanced
802 pages
19h 30m
English
Here is the code fragment that creates a connection to the local PostgreSQL database:
String URL = "jdbc:postgresql://localhost/cookbook";Properties prop = new Properties( );//prop.put( "user", "cook" );//prop.put( "password", "secretPass123" );Connection conn = DriverManager.getConnection(URL, prop);
The commented lines show how you can set a user and password for your connection. Since, for this demonstration, we are keeping the database open and accessible to anyone, we could use an overloaded DriverManager.getConnection(String url) method. However, we will show the most general implementation that would allow anyone to read from a property file and pass other useful values (ssl as true/false, autoReconnect as true/false, ...
Read now
Unlock full access