Guest User

JDBC Test

a guest
Feb 4th, 2020
124
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.sql.*; import java.util.*;
  2. public class DBTest {
  3.     public static void main(String[] args) {
  4.         log("DBTest is running.");
  5.         try {
  6.             Class.forName("org.postgresql.Driver");
  7.             //Scanner sc=new java.util.Scanner(System.in);
  8.             //String c=sc.nextLine();
  9.             Connection a=DriverManager.getConnection("jdbc:postgresql://db:5432/?user=postgres");
  10.             Statement b=a.createStatement();
  11.             //b.executeQuery("insert into info(id,data) values (1,'hello'), (5,'x');");
  12.         } catch(SQLException e) {
  13.             System.err.println("SQL exception: "+e.getMessage());
  14.             System.exit(e.getMessage().hashCode());
  15.         } catch(Exception e) {
  16.             System.err.println("Exception: "+e.getMessage());
  17.             System.exit(99);
  18.         }
  19.     }
  20.     private static void log(String p) {
  21.         System.out.println(p);
  22.     }
  23. }
RAW Paste Data