Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bean;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- /**
- *
- * @author Kelvin Eger
- */
- public class AlterarBean {
- private Connection connect = null;
- private Statement statement = null;
- private PreparedStatement preparedStatement = null;
- private ResultSet resultSet = null;
- public String getFormUpdate(String codigo){
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connect = DriverManager.getConnection("jdbc:mysql://localhost/demonstracao?user=root&password");
- preparedStatement = connect.prepareStatement("select * from demonstracao.pessoa where codigo = ?");
- preparedStatement.setString(1, codigo);
- resultSet = preparedStatement.executeQuery();
- return criaFormularioHtml(resultSet);
- } catch (Exception e ) {
- e.printStackTrace();
- }
- return "Erro ao consultar o registro.";
- }
- private String criaFormularioHtml(ResultSet resultSet) throws SQLException{
- resultSet.next();
- String valores = "";
- valores += "<div style=\"border:5px solid black; background-color: #d6e2ee; text-align: center;\">";
- valores += "<table border=6 align=center cellspacing=0 cellpadding=2 bordercolor=\"020305\">";
- valores += "<tr> <h2><font color=\"black\">Altere Seu Nome de Cadastro</font></h2> </tr>";
- valores += "<form action=\"AlterarCadastro\" method=\"post\">";
- valores +="<tr>";
- valores += "<td>";
- valores += "Código:";
- valores += "<input type=\"text\" name=\"codigo\" readonly=\"readonly\" value=\""+resultSet.getInt("codigo")+"\"><br />";
- valores += "</td>";
- valores += "<tr>";
- valores += "<td>";
- valores += "Nome: <input type=\"text\" name=\"nome\" value=\""+resultSet.getString("nome")+"\"><br />";
- valores += "</td>";
- valores +="<tr>";
- valores += "<td>";
- valores += "Usuário:";
- valores += "<input type=\"text\" name=\"username\" value=\""+resultSet.getString("username")+"\"><br />";
- valores += "</td>";
- valores +="<tr>";
- valores += "<td>";
- valores += "E-mail:";
- valores += "<input type=\"text\" name=\"email\" value=\""+resultSet.getString("email")+"\"><br />";
- valores += "</td>";
- valores += "<tr width=1500>";
- valores += "<td align=center >";
- valores += "<input type=\"submit\" value=\"Alterar\" name=\"alterar\">";
- valores += "<input type=\"submit\" value=\"Cancelar\" name=\"cancelar\">";
- valores += "</td>";
- valores += "</tr>";
- valores += "</form>";
- return valores;
- }
- }
Add Comment
Please, Sign In to add comment