SHARE
TWEET

Untitled

a guest May 22nd, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <%
  2.     String co=request.getParameter("txtCodigo");
  3.     int qt = Integer.parseInt(request.getParameter("txtQuantidade"));
  4. %>
  5. <html>
  6.     <head>
  7.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8.         <title>Prova JSP</title>
  9.     </head>
  10.     <body>
  11.         <center><h1>Consulta de Produtos</h1></center>
  12.         <%@ page import="java.sql.*" %>
  13.         <%
  14.         String pre;
  15.         try {
  16.                 Class.forName("com.mysql.jdbc.Driver");
  17.                 Connection con=DriverManager.getConnection("jdbc:mysql://localhost/prova","root","1q2w3e77");
  18.                 Statement st=con.createStatement();
  19.                 //st.execute("create table Produto(codigo int, nome varchar(40), preco double)");
  20.                 //st.execute("insert into Produto values(1,'queijo minas - kg',12.50)");
  21.                 ResultSet rs=st.executeQuery("select codigo,preco from Produto where codigo="+co);
  22.                     while (rs.next()) {
  23.                         //cod=rs.getString("codigo");
  24.                         pre=rs.getString("preco");
  25.         %>
  26.         <hr />
  27.             Pre├žo: <%=pre * qt%><br />
  28.             <%
  29.             }
  30.             st.close();
  31.             con.close();
  32.             }
  33.             catch (Exception e) {
  34.                 out.write("Erro: "+e.getMessage());
  35.             }
  36.             %>
  37.     </body>
  38. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top