import java.sql.*; import java.io.*; public class Baasioma{ public static void main(String argumendid[]) throws Exception{ Class.forName("org.gjt.mm.mysql.Driver"); Connection cn=DriverManager.getConnection( "jdbc:mysql:/localhost/info", "", ""); Statement st=cn.createStatement(); boolean g=true; while (g==true){ String lause="SELECT count(*) as kogus FROM autod;"; ResultSet rs=st.executeQuery(lause); rs.next(); System.out.println("Baasis on "+rs.getInt("kogus")+" autot!"); String lause1="SELECT auto_id, mark, mudel, v_aasta FROM autod;"; ResultSet rs1=st.executeQuery(lause1); while(rs1.next()){ System.out.println(rs1.getString("auto_id")+" "+rs1.getString("mark")+" "+rs1.getString("mudel")+" v-laske aasta: "+rs1.getString("v_aasta")+" "); } BufferedReader sisse=new BufferedReader( new InputStreamReader(System.in) ); System.out.println("Kui tahad oma auto andmed lisada siis valik - 4"); System.out.println("Kas sa tahad olemasolevate autode kohta lisaandmeid?"); System.out.println("Tehniliste n2itajate valik - 1"); System.out.println("Parima veerandmiili näitajate valik - 2"); System.out.println("Tahad v2ljuda - 3"); String lause2=sisse.readLine(); if (lause2.equals("4")){ BufferedReader sisse2=new BufferedReader( new InputStreamReader(System.in) ); System.out.println("Palun sisesta oma auto andmed!"); System.out.println("Mark:"); String mark=sisse2.readLine(); System.out.println("Mudel:"); String mudel=sisse2.readLine(); System.out.println("V2ljalaskeaasta:"); String vlase=sisse2.readLine(); String lause7="Insert into autod set mark='"+mark+"', mudel='"+mudel+"', v_aasta='"+vlase+"'"; st.executeUpdate(lause7); System.out.println("Oma auto j2rjekorranumber:"); String aid=sisse2.readLine(); System.out.println("Toomaht kuuptollides:"); String toomaht=sisse2.readLine(); System.out.println("Voimsus:"); String voimsus=sisse2.readLine(); System.out.println("Auto v2rv:"); String varv=sisse2.readLine(); String lause8="Insert into auto_andmed set auto_id='"+aid+"', toomaht='"+toomaht+"', varv='"+varv+"', voimsus='"+voimsus+"'"; st.executeUpdate(lause8); } if (lause2.equals("1")){ BufferedReader sisse1=new BufferedReader( new InputStreamReader(System.in) ); System.out.println("Palun vali auto j2rjekorranumbri j2rgi!"); String lause3=sisse1.readLine(); String lause4="Select toomaht, varv, voimsus FROM auto_andmed WHERE auto_id='"+lause3+"';"; ResultSet rs3=st.executeQuery(lause4); //rs3.next(); if (!rs3.next()){ System.out.println("Selle auto kohta andmed puuduvad!"); }else{ System.out.println("Selle auto mootori toomaht on "+rs3.getString("toomaht")+" CID-i ehk kuuptolli ja mootoril on voimsust "+rs3.getString("voimsus")+" hobujoudu! Auto v2rv on "+rs3.getString("varv")+"!"); } } if (lause2.equals("2")){ BufferedReader sisse2=new BufferedReader( new InputStreamReader(System.in) ); System.out.println("Palun vali auto j2rjekorranumbri j2rgi!"); String lause5=sisse2.readLine(); String lause6="Select RT, sixft, ET, loppkiirus FROM ajad WHERE auto_id='"+lause5+"';"; ResultSet rs4=st.executeQuery(lause6); //rs4.next(); if (!rs4.next()){ System.out.println("Selle auto kohta andmed puuduvad!"); }else{ System.out.println("Antud on parimad näitajad veerandmiilil!"); System.out.println("RT "+rs4.getString("RT")+", 60 jala aeg "+rs4.getString("sixft")+", ET "+rs4.getString("ET")+" ja loppkiirus "+rs4.getString("loppkiirus")+"!"); } } if (lause2.equals("3")){ g=false; cn.close(); } } } }