Guest User

Untitled

a guest
Mar 13th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. import java.io.BufferedInputStream;
  2. import java.io.DataInputStream;
  3. import java.io.EOFException;
  4. import java.io.FileInputStream;
  5. import java.io.IOException;
  6. import java.sql.*;
  7. import java.io.*;
  8. import java.util.*;
  9.  
  10. public class baza_2 {
  11.         public static void main(String[] args)throws IOException{
  12.                 String nazwisko;
  13.                 int kwota;
  14.  
  15.                 String url = "jdbc:postgresql://localhost/baza?user=login&password=haslo";
  16.                 try {
  17.                     Class.forName("org.postgresql.Driver");
  18.                     Connection db = DriverManager.getConnection(url);
  19.  
  20.                     Statement st = db.createStatement();
  21.  
  22.  
  23.                     st.executeUpdate("UPDATE dane SET kwota=kwota+10 WHERE miesiac='3';");
  24.                     ResultSet rs = st.executeQuery("SELECT * FROM dane;");
  25.  
  26.                     while (rs.next()) {
  27.                         System.out.printf("Nazwisko: ");
  28.                         System.out.println(rs.getString(1));
  29.                         System.out.printf("Miesiac : ");
  30.                         System.out.println(rs.getInt   (2));
  31.                         System.out.printf("Kwota   : ");
  32.                         System.out.println(rs.getInt   (3));
  33.                         System.out.println("\n");
  34.                     }
  35.                     rs.close();
  36.                     st.close();
  37.  
  38.                 } catch (SQLException e) {
  39.                     System.err.println("Wyjatek z zapytania SQL: " + e.getMessage());
  40.                     e.printStackTrace(System.err);
  41.                 } catch (ClassNotFoundException e) {
  42.                     System.err.println("Wyjatek przy ladowaniu klas: " + e.getMessage());
  43.                     e.printStackTrace(System.err);
  44.                 }
  45.  
  46.             }
  47. }
Add Comment
Please, Sign In to add comment