Вы находитесь на странице: 1из 7

package bojan;

import java.util.Vector;

import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; import java.util.Vector;

public class DBF { public static Vector<Predmet> getPredmet(){ Vector<Predmet> res = new Vector<Predmet>(); Statement stmt = null; ResultSet rs = null; try{ stmt = DBConnection.getConnection().createStatement(); rs = stmt.executeQuery("select sfrPredmet,nazivPredmet from PREDMET"); Predmet temp = null; while(rs.next()){ temp = new Predmet(); temp.sfrPredmet = rs.getInt(1); temp.nazivPredmet = rs.getString(2); res.add(temp); } }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(rs !=null){ rs.close(); } }catch(Exception e){

e.printStackTrace(); } } return res; }

public static Vector<IspitniRok> getIspitniRok(){ Vector<IspitniRok> res = new Vector<IspitniRok>(); Statement stmt = null; ResultSet rs = null; try{ stmt = DBConnection.getConnection().createStatement(); rs = stmt.executeQuery("select sfrIspitniRok, nazivIspitniRok from ISPITNIROK"); IspitniRok temp = null; while(rs.next()){ temp = new IspitniRok(); temp.sfrIspitniRok = rs.getInt(1); temp.nazivIspitniRok = rs.getString(2); res.add(temp); } }catch(Exception e){ e.printStackTrace(); }return res; }

public static Vector<Profil> getProfil(){ Vector<Profil> res = new Vector<Profil>(); Statement stmt = null; ResultSet rs = null; try{ stmt = DBConnection.getConnection().createStatement(); rs = stmt.executeQuery("select sfrProfil, nazivProfil from PROFIL");

Profil temp = null; while(rs.next()){ temp = new Profil(); temp.sfrProfil = rs.getInt(1); temp.nazivProfil = rs.getString(2); res.add(temp); } }catch(Exception e){ e.printStackTrace(); }return res; }

public static Vector<Plan> getPlan(){ Vector<Plan> res = new Vector<Plan>(); Statement stmt = null; ResultSet rs = null; try{ stmt = DBConnection.getConnection().createStatement(); rs = stmt.executeQuery("select sfrPlan, nazivPlan from PLAN"); Plan temp = null; while(rs.next()){ temp = new Plan(); temp.sfrPlan = rs.getInt(1); temp.nazivPlan = rs.getString(2); res.add(temp); } }catch(Exception e){ e.printStackTrace(); }return res; }

public static Vector<Nastavnik> getNastavnik(){

Vector<Nastavnik> res = new Vector<Nastavnik>(); Statement stmt = null; ResultSet rs = null; try{ stmt = DBConnection.getConnection().createStatement(); rs = stmt.executeQuery("SELECT SFRNASTAVNIK, IME, PREZIME FROM baze2vezbe.NASTAVNIK"); Nastavnik temp = null; while(rs.next()){ temp = new Nastavnik(); temp.sfrNastavnik = rs.getInt(1); temp.ime = rs.getString(2); temp.prezime = rs.getString(3); res.add(temp); } }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(rs !=null){ rs.close(); } }catch(Exception e){ e.printStackTrace(); } } return res; }

public static Vector<Prijava> getPrijava(int brind){ Vector<Prijava> res = new Vector<Prijava>(); Statement stmt = null;

ResultSet rs = null; try{ stmt = DBConnection.getConnection().createStatement(); rs = stmt.executeQuery("SELECT i.NAZIVISPITNIROK,p.NAZIVPLAN,pr.NAZIVPREDMET,pf.NAZIVPROFIL,pj.OCENA,pj.BROJ " + " FROM baze2vezbe.ISPITNIROK i, baze2vezbe.PLAN p, baze2vezbe.PREDMET pr, baze2vezbe.PROFIL pf, baze2vezbe.PRIJAVA pj " + " WHERE i.SFRISPITNIROK=pj.SFRISPITNIROK AND p.SFRPLAN=pj.SFRPLAN AND pf.SFRPROFIL=pj.SFRPROFIL AND pr.SFRPREDMET=pj.SFRPREDMET AND pj.BROJ =" + brind); Prijava temp = null; while(rs.next()){ temp = new Prijava(); temp.nazivIspitniRok = rs.getString(1); temp.nazivProfil = rs.getString(2); temp.nazivPlan = rs.getString(3); temp.nazivPredmet = rs.getString(4); temp.ocena = rs.getInt(5); temp.broj = rs.getInt(6); res.add(temp); } }catch(Exception e){ e.printStackTrace(); } return res; }

public static boolean insertPrijava(int broj, int sfrPredmet, int sfrIspitniRok, int sfrProfil, int sfrPlan, int ocena, int sfrNastavnik){ PreparedStatement pstmt = null; try{ DBConnection.getConnection().setAutoCommit(false); pstmt = DBConnection.getConnection().prepareStatement("INSERT INTO PRIJAVA (broj, sfrPredmet, sfrIspitniRok, sfrProfil, sfrPlan, ocena, sfrNastavnik)" + "VALUES (?,?,?,?,?,?,?)");

pstmt.setInt(1, broj); pstmt.setInt(2, sfrPredmet); pstmt.setInt(3, sfrIspitniRok); pstmt.setInt(4, sfrProfil); pstmt.setInt(5, sfrPlan); pstmt.setInt(6, ocena); pstmt.setInt(7, sfrNastavnik); int i = pstmt.executeUpdate(); DBConnection.getConnection().commit(); return true; }catch(Exception e){ e.printStackTrace(); }return false; }

public static boolean deletePrijava(int broj,int sfrPredmet, int sfrIspitniRok, int sfrProfil, int sfrPlan){ boolean res = false; PreparedStatement pstmt = null; try{ DBConnection.getConnection().setAutoCommit(false); pstmt = DBConnection.getConnection().prepareStatement("DELETE FROM PRIJAVA WHERE (broj=? and sfrPredmet=? and sfrIspitniRok=? and sfrProfil=? and sfrPlan=?)"); pstmt.setInt(1, broj); pstmt.setInt(2, sfrPredmet); pstmt.setInt(3, sfrIspitniRok); pstmt.setInt(4, sfrProfil); pstmt.setInt(5, sfrPlan); int pr = pstmt.executeUpdate(); DBConnection.getConnection().commit(); res = true; }catch(Exception e){ e.printStackTrace();

}return res; }

Вам также может понравиться