Skocz do zawartości

Adalberd

Użytkownik
  • Postów

    1
  • Dołączył

  • Ostatnia wizyta

Treść opublikowana przez Adalberd

  1. Witam, poniżej sa 4 zadania tego samego typu. w każdym kawałku kodu są błędy które trzeba znaleźć. Nie są to literówki ani np brak zamknięcia/otwarcia {} Sa to błędy logiczne np brak linijki kodu, lub linijka kodu nie jest dokończona (przykład pokazuje w zad. 2 na niebiesko) W każdym zadaniu błędy są bardzo podobne i jest ich minimum 4 W razie możliwości bardzo proszę o pomoc. Bedę wdzięczny i napewno piwko postawię no chyba ze inna miejscowowść to wyśle :) Z góry bardzo dziękuję i przepraszam za skład kodu. Zadanie 1 protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Connection db_conn; Statement db_stmt; try { Class.forName ("com.mysql.jdbc.Driver"); Properties db_props = new Properties (); db_props.setProperty ("user", "test"); db_props.setProperty ("password", "0101test0101"); db_props.setProperty ("charSet", "iso-8859-2"); String db_url = new String ("jdbc:mysql://bazy.kil.szkola.pl/test"); db_conn = DriverManager.getConnection (db_url, db_props); ResultSet rs = db_conn.executeQuery (query); if (rs.getString (1) == "aaa") { response.sendRedirect (http://www.google.pl); } } db_conn.close(); // 1 błąd-brakowało zamknięcia pętli Try catch (SQLException e) { out.println ("Wyjątek sql: " + e.toString ()); } catch (ClassNotFoundException e) { out.println ("Wyjątek - nie ma takiej klasy: " + e.toString ()); } catch (Exception e) { out.println ("Inny wyjątek: " + e.toString ()); } } Zadanie 2 protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType ("text/html; charset=ISO-8859-2"); PrintWriter out;response.getWriter(); // tego brakowało Connection db_conn; Statement db_stmt; try { Properties db_props = new Properties (); db_props.setProperty ("user", "test"); db_props.setProperty ("password", "0101test0101"); db_props.setProperty ("charSet", "iso-8859-2"); String db_url = new String ("jdbc:mysql://bazy.kil.szkola.pl/test"); db_conn = DriverManager.getConnection(db_props); db_stmt = db_conn.createStatement (); ResultSet rs = db_stmt.executeUpdate ("SELECT * FROM users;"); while (rs.next ()) { out.println ("<p>Użytkownik: "+rs.getString(1)+" Hasło: "+rs.getString (2)+"</p>"); } db_conn.close (); } catch (Exception e) { out.println ("Inny wyjątek: " + e.toString ()); } catch (SQLException e) { out.println ("Wyjątek sql: " + e.toString ()); } catch (ClassNotFoundException e) { out.println ("Wyjątek - nie ma takiej klasy: " + e.toString ()); } finally { out.close (); } } Zadanie 3 throws servl etExcepti on , IOException { response.setContentType C"text/html; charset=ISO-8859-2"); printwriter out=response.getwriterC); Connection db_conn; Statement db_stmt; try { properties db_props = new pro p, erties C); db_props.setproperty C"user', "test"); db_props.setproperty C"password", "OlOltest010l"); db_props.setproperty C"charset", "iso-8859-2"); string db_url = new string C"jdbc:mysql://bazy.kil.szkola.pl/test"); db_conn = DriverManager.getconnection(db_url); db_stmt = db_conn.createstatement C); string query="sELECT * FROM users;" db_stmt.executeQuery Cquery); while Crs.next C)) { out.println C"<p>użytkownik: "+rs.getstringCl)+" "+rs.getstring (2)+"</p>"); response.sendRedirectC..http://www.google.pl..); } db_conn.close C); } catch CException e) { out.println C"Inny wyj:ttek: " + e.tostring O); } catch CSQLException e) { out.println C"wyj:ttek sql: II + e.tostring O); } . catch CClassNotFoundExceptlon e) { out.println C"wyj:ttek - nie ma takiej klasy: " + e.tostring O); } } Zadanie 4 protected void dopost (HttpservletRequest request, HttpServletResponse response) throws servletException, IOException { response.setContentType ("text/html; charset=ISO-8859-2"); Connection db_conn; class.forName("com.mysql.jdbc.Driver"); properties db_props; db_props.setproperty ("user", "test"); db_props.setproperty ("password", "OlOltest010l"); db_props.setproperty ("charSet", "iso-8859-2"); string db_url = new string ("jdbc:mysql://bazy.kil.szkola.pl/test"); db_conn = DriverManager.getconnection(db_url,db_props); Resultset rs = db_conn.executeupdate ("SELECT * FROM users where login='"+request.getAttribute("login")+", and pass='''+request.getAttribute("pass")+"';''); if (rs.next O) { Httpsession session; session.setAttribute("login",request.getParameter("login")); } } db_conn.close ();
×
×
  • Dodaj nową pozycję...