Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. <% if(request.getParameter("acao") == null){ %>
  2. <form method="post" action="cadBairro.jsp?acao=gravar">
  3. <table width="337" height="62" border="0" align="center" cellpadding="0" cellspacing="0">
  4.   <tr>
  5.     <td width="148" align="right">Nome : </td>
  6.     <td width="183"><label>
  7.       <input name="nome" type="text" id="nome" maxlength="20" />
  8.     </label></td>
  9.   </tr>
  10.   <tr>
  11.     <td colspan="2" align="center">
  12.       <input type="reset" name="Reset" id="button" value="Limpar" />
  13.       <input name="input" type="submit" value="Enviar" /></td>
  14.     </tr>
  15. </table>
  16. </form>
  17.  
  18. <% }else{
  19.          if ((request.getParameter("nome").length() <= 0) )
  20.          {
  21.             //out.println("Preencha os campos corretamente!");
  22.             response.sendRedirect("cadBairro.jsp");
  23.          }else{
  24.    try
  25.    {
  26.      Class.forName ("org.postgresql.Driver");
  27.      
  28.      Connection con = DriverManager.getConnection ("jdbc:postgresql://localhost/aulas_daniel","postgres","Senac2010");
  29.  
  30.      Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
  31.      
  32.      
  33.      
  34.     st.executeUpdate("INSERT INTO bairro (bai_nome) VALUES ('"+request.getParameter("nome")+"')");
  35.    
  36.     out.println("Bairro cadastrado com sucesso!");
  37.    
  38.    
  39.     }
  40.     catch (ClassNotFoundException erroClass)
  41.    {
  42.       out.println ("Classe Driver JDBC não foi localizado, erro = " +erroClass);
  43.    }
  44.    catch (SQLException erroSQL)
  45.    {
  46.       out.println("Erro de conexão com o Banco de Dados, erro = "+erroSQL);
  47.    }
  48.    }
  49.    }
  50. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement