Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedInputStream;
- import java.io.DataInputStream;
- import java.io.EOFException;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.sql.*;
- import java.io.*;
- import java.util.*;
- public class baza_3 {
- void zwieksz(Statement st, String miesiac){
- try{
- st.executeUpdate("UPDATE dane SET kwota=kwota+10 WHERE miesiac='"+miesiac+"';");
- } catch (SQLException e) {
- System.err.println("Wyjatek z zapytania SQL: " + e.getMessage());
- e.printStackTrace(System.err);
- }
- }
- void wydruk(Statement st){
- try{
- ResultSet rs = st.executeQuery("SELECT * FROM dane;");
- while (rs.next()) {
- System.out.printf("Nazwisko: ");
- System.out.println(rs.getString(1));
- System.out.printf("Miesiac : ");
- System.out.println(rs.getInt(2));
- System.out.printf("Kwota : ");
- System.out.println(rs.getInt(3));
- System.out.println("\n");
- }
- rs.close();
- } catch (SQLException e) {
- System.err.println("Wyjatek z zapytania SQL: " + e.getMessage());
- e.printStackTrace(System.err);
- }
- }
- public static void main(String[] args)throws IOException{
- baza_3 baza = new baza_3();
- String url = "jdbc:postgresql://localhost/baza?user=login&password=haslo";
- try{
- Class.forName("org.postgresql.Driver");
- Connection db = DriverManager.getConnection(url);
- Statement st = db.createStatement();
- baza.zwieksz(st, args[0]);
- baza.wydruk(st);
- st.close();
- } catch (SQLException e) {
- System.err.println("Wyjatek z zapytania SQL: " + e.getMessage());
- e.printStackTrace(System.err);
- } catch (ClassNotFoundException e) {
- System.err.println("Wyjatek przy ladowaniu klas: " + e.getMessage());
- e.printStackTrace(System.err);
- }
- }
- }
Add Comment
Please, Sign In to add comment