Kelvineger

Untitled

Jun 30th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. package bean;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9.  
  10. /**
  11. *
  12. * @author Kelvin Eger
  13. */
  14. public class AlterarBean {
  15. private Connection connect = null;
  16. private Statement statement = null;
  17. private PreparedStatement preparedStatement = null;
  18. private ResultSet resultSet = null;
  19.  
  20. public String getFormUpdate(String codigo){
  21. try {
  22. Class.forName("com.mysql.jdbc.Driver");
  23.  
  24. connect = DriverManager.getConnection("jdbc:mysql://localhost/demonstracao?user=root&password");
  25.  
  26. preparedStatement = connect.prepareStatement("select * from demonstracao.pessoa where codigo = ?");
  27.  
  28. preparedStatement.setString(1, codigo);
  29. resultSet = preparedStatement.executeQuery();
  30. return criaFormularioHtml(resultSet);
  31. } catch (Exception e ) {
  32. e.printStackTrace();
  33. }
  34. return "Erro ao consultar o registro.";
  35. }
  36.  
  37. private String criaFormularioHtml(ResultSet resultSet) throws SQLException{
  38.  
  39. resultSet.next();
  40.  
  41. String valores = "";
  42.  
  43. valores += "<div style=\"border:5px solid black; background-color: #d6e2ee; text-align: center;\">";
  44. valores += "<table border=6 align=center cellspacing=0 cellpadding=2 bordercolor=\"020305\">";
  45. valores += "<tr> <h2><font color=\"black\">Altere Seu Nome de Cadastro</font></h2> </tr>";
  46. valores += "<form action=\"AlterarCadastro\" method=\"post\">";
  47.  
  48.  
  49.  
  50. valores +="<tr>";
  51. valores += "<td>";
  52. valores += "Código:";
  53. valores += "<input type=\"text\" name=\"codigo\" readonly=\"readonly\" value=\""+resultSet.getInt("codigo")+"\"><br />";
  54. valores += "</td>";
  55.  
  56. valores += "<tr>";
  57. valores += "<td>";
  58. valores += "Nome: <input type=\"text\" name=\"nome\" value=\""+resultSet.getString("nome")+"\"><br />";
  59. valores += "</td>";
  60.  
  61. valores +="<tr>";
  62. valores += "<td>";
  63. valores += "Usuário:";
  64. valores += "<input type=\"text\" name=\"username\" value=\""+resultSet.getString("username")+"\"><br />";
  65. valores += "</td>";
  66.  
  67. valores +="<tr>";
  68. valores += "<td>";
  69. valores += "E-mail:";
  70. valores += "<input type=\"text\" name=\"email\" value=\""+resultSet.getString("email")+"\"><br />";
  71. valores += "</td>";
  72.  
  73. valores += "<tr width=1500>";
  74. valores += "<td align=center >";
  75. valores += "<input type=\"submit\" value=\"Alterar\" name=\"alterar\">";
  76. valores += "<input type=\"submit\" value=\"Cancelar\" name=\"cancelar\">";
  77. valores += "</td>";
  78. valores += "</tr>";
  79. valores += "</form>";
  80.  
  81. return valores;
  82. }
  83. }
Add Comment
Please, Sign In to add comment