Results 1 to 3 of 3
  1. #1
    poliocertes is offline Member
    Join Date
    Dec 2013
    Posts
    13
    Rep Power
    0

    Default how to transfer postgrsql query into jdbc

    I have z small java program which working with postgres database. I;m faced with last isseu before finish. How to use a postgres query:

    INSERT INTO rozliczenie(id_pracow, liczba_dni_przepracowanych, liczba_dni_nieobecnosci, liczba_dni_urlopu, liczba_dni_choroby)
    VALUES
    ((SELECT id_pracownika FROM pracownicy WHERE imie='Bogdan' AND nazwisko='Nowak' ),(SELECT COUNT(*) FROM grafik WHERE status='1' AND id_pracownika='1' AND czy_rozliczony='0' ),(SELECT COUNT(*) FROM grafik WHERE status='2' AND id_pracownika='1' AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='3' AND id_pracownika='1'AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='4' AND id_pracownika='1' AND czy_rozliczony='0')),

    ((SELECT id_pracownika FROM pracownicy WHERE imie='Cezary' AND nazwisko='Kowalski'),(SELECT COUNT(*) FROM grafik WHERE status='1' AND id_pracownika='2'AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='2' AND id_pracownika='2' AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='3' AND id_pracownika='2' AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='4' AND id_pracownika='2' AND czy_rozliczony='0')),

    ((SELECT id_pracownika FROM pracownicy WHERE imie='Anna' AND nazwisko='Pawlak' ),(SELECT COUNT(*) FROM grafik WHERE status='1' AND id_pracownika='3' AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='2' AND id_pracownika='3' AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='3' AND id_pracownika='3' AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='4' AND id_pracownika='3' AND czy_rozliczony='0')),

    ((SELECT id_pracownika FROM pracownicy WHERE imie='Agnieszka' AND nazwisko='Orlowska' ),(SELECT COUNT(*) FROM grafik WHERE status='1' AND id_pracownika='4' AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='2' AND id_pracownika='4' AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='3' AND id_pracownika='4' AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='4' AND id_pracownika='4' AND czy_rozliczony='0')),

    ((SELECT id_pracownika FROM pracownicy WHERE imie='Joanna' AND nazwisko='Tomczyk' ),(SELECT COUNT(*) FROM grafik WHERE status='1' AND id_pracownika='5' AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='2' AND id_pracownika='5' AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='3' AND id_pracownika='5' AND czy_rozliczony='0'),(SELECT COUNT(*) FROM grafik WHERE status='4' AND id_pracownika='5' AND czy_rozliczony='0'));
    in java program? I don't know even how to start with this. Code is ok and working properly into pgadmin3.
    Last edited by poliocertes; 12-16-2013 at 09:43 PM.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,277
    Rep Power
    6

    Default Re: how to transfer postgrsql query into jdbc

    Well it starts with learning about the JDBC API. Plenty of resources available on the net.

    Trail: JDBC(TM) Database Access (The Java™ Tutorials)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,183
    Rep Power
    20

    Default Re: how to transfer postgrsql query into jdbc

    That would be a single statement, inserting a single row, which you would then batch up the data for the 5 rows you want to insert.
    You will want to be using a PreparedStatement.

    That should give you enough terms to look up via that tutorial.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Java JDBC - Display Multiple Query Results in one GUI
    By nov072008 in forum AWT / Swing
    Replies: 5
    Last Post: 10-06-2011, 06:03 PM
  2. MySQL JDBC query returns no response
    By PDXErik in forum New To Java
    Replies: 1
    Last Post: 08-20-2010, 10:07 AM
  3. JDBC Query
    By KumbhaniMehul in forum Java Servlet
    Replies: 1
    Last Post: 04-07-2010, 04:41 AM
  4. Mysql/JDBC update query problem
    By thelinuxguy in forum Advanced Java
    Replies: 3
    Last Post: 02-11-2009, 10:56 PM
  5. ms access jdbc query problem
    By Fleur in forum New To Java
    Replies: 2
    Last Post: 04-30-2008, 07:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •