Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- compile: javac DatabaseConnectionDemo.java
- execute: java -cp .;lib\postgresql-X.X.XXXX.jar DatabaseConnectionDemo
- */
- //package io.uetoyo.gists;
- import java.sql.Connection;
- import java.sql.SQLException;
- import java.sql.DriverManager;
- class DatabaseConnectionDemo {
- public static void main(String[] args) {
- Connection connection = null;
- String url = "jdbc:postgresql://SERVER_NAME/DATABASE_NAME";
- try {
- connection = DriverManager.getConnection(url, "USER", "PASSWORD");
- System.out.println("Success");
- } catch (SQLException ex) {
- System.out.println("Error");
- } finally {
- if (connection != null) {
- try {
- connection.close();
- } catch (SQLException ex) {
- // Handle or ignore the exception.
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement