IT-Academy

JAVA JDBC

Apr 21st, 2022
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. /*
  2.  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  3.  * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
  4.  */
  5. package sk.stu.fiit;
  6.  
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.SQLException;
  10. //import java.sql.*;
  11.  
  12. /**
  13.  *
  14.  * @author Administrator
  15.  */
  16. public class DB_Tester {
  17.  
  18.     private final String url = "jdbc:postgresql://localhost/testovacia";
  19.     private final String pouzivatel = "postgres";
  20.     private final String heslo = "20626mir.";
  21.  
  22.     /**
  23.      * @param args the command line arguments
  24.      */
  25.     public static void main(String[] args) {
  26.         // TODO code application logic here
  27.         DB_Tester dbtest = new DB_Tester();
  28.         dbtest.connect();
  29.     }
  30.  
  31.     private void connect() {
  32.         Connection conn = null;
  33.         try {
  34.             conn = DriverManager.getConnection(url, pouzivatel, heslo);
  35.             System.out.println("Gratulujem si sa pripojil...");
  36.             conn.close();
  37.         } catch (SQLException exSQL) {
  38.             System.out.println("Nepripojil som sa - " + exSQL.getMessage());
  39.         }
  40.  
  41.     }
  42.  
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment