Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class Runner {
  4.     public static void main(String[] args) throws SQLException {
  5.         Connection conn = null;
  6.         Statement stmt = null;
  7.         try {
  8.             Class.forName("org.postgresql.Driver");
  9.             conn = DriverManager
  10.                     .getConnection("jdbc:postgresql://localhost:5432/projekt_DBS",
  11.                             "bruno", "fiit");
  12.             conn.setAutoCommit(false);
  13.             System.out.println("Opened database successfully");
  14.             stmt = conn.createStatement();
  15.             ResultSet rs = stmt.executeQuery("SELECT * FROM cesta LIMIT 1;");
  16.             rs.next();
  17.             int pocet = rs.getInt("id_linka");
  18.             System.out.println(pocet);
  19.  
  20.  
  21.             rs.close();
  22.             stmt.close();
  23.             conn.close();
  24.         } catch (Exception e) {
  25.             System.err.println(e.getClass().getName() + ": " + e.getMessage());
  26.             System.exit(0);
  27.         }
  28.         System.out.println("Operation done successfully");
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement