package oad; import oad.*; import java.sql.*; import java.io.*; import junit.framework.*; public class Baasiuba2 extends TestCase { Connection cn; Statement st; int tester=0; public Baasiuba2() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); cn=DriverManager.getConnection("jdbc:odbc:andmebaas", "", ""); st=cn.createStatement(); }catch(Exception e){ System.out.println(e); } } public String kysiPealkiri(int id) throws SQLException { String lause="SELECT * FROM raamatud where id="+id+";"; ResultSet rs=st.executeQuery(lause); rs.next(); return rs.getString("pealkiri"); } public String kysiAutor(int id) throws SQLException { String lause="SELECT * FROM raamatud where id="+id+";"; ResultSet rs=st.executeQuery(lause); rs.next(); return rs.getString("autor"); } public String kysiKirjastus(int id) throws SQLException { String lause="SELECT * FROM kirjastused where id="+id+";"; ResultSet rs=st.executeQuery(lause); rs.next(); return rs.getString("kirjastus"); } public int kysiAasta(int id) throws SQLException { String lause="SELECT * FROM info where id="+id+";"; ResultSet rs=st.executeQuery(lause); rs.next(); return rs.getInt("aasta"); } public int kysiLk(int id) throws SQLException { String lause="SELECT * FROM info where id="+id+";"; ResultSet rs=st.executeQuery(lause); rs.next(); return rs.getInt("lk"); } public int kysiHind(int id) throws SQLException { String lause="SELECT * FROM info where id="+id+";"; ResultSet rs=st.executeQuery(lause); rs.next(); return rs.getInt("hind"); } public int kysiMitu() throws SQLException { int loend=0; String lause="SELECT * FROM raamatud;"; ResultSet rs=st.executeQuery(lause); while(rs.next()) { loend++; } if(loend!=0)tester=1; return loend; } /* * Mingid Testid */ public void testkysiMitu() throws SQLException { int loend=0; String lause="SELECT * FROM raamatud;"; ResultSet rs=st.executeQuery(lause); while(rs.next()) { loend++; } if(loend!=0)tester=1; assertEquals(1, tester); tester=0; } public void testkysiPealkiri() throws SQLException { String lause="SELECT pealkiri FROM raamatud;"; ResultSet rs=st.executeQuery(lause); rs.next(); if(rs.getString("pealkiri")!="")tester=1; assertEquals(1, tester); tester=0; } public void testkysiHind() throws SQLException { String lause="SELECT hind FROM info;"; ResultSet rs=st.executeQuery(lause); rs.next(); if(rs.getInt("hind")!=0)tester=1; assertEquals(1, tester); tester=0; } public void testkysiAasta() throws SQLException { String lause="SELECT aasta FROM info;"; ResultSet rs=st.executeQuery(lause); rs.next(); if(rs.getInt("aasta")!=0)tester=1; assertEquals(1, tester); tester=0; } public static void main(String[] argumendid){ junit.textui.TestRunner.run(new TestSuite(Baasiuba2.class)); } }