Popular combobox via a bank consultation

Asked

Viewed 573 times

0

Guys I know I’m doing it the wrong way to popular my combobox, I’m doing it on the client side instead of on the server side is that java is not my thing .

I’m trying to popular my combobox as follows: But of error cannot find Symbol class connect just below the Try on the connected connection line = new Bancodedados.();

 <select name = "usuario">
                                     <%
                                        try {
                                        Connection conexao = new BancoDeDados.conectar();
                                        Statement stmt = conexao.createStatement();
                                        ResultSet rs; 
                                        //rs = stmt.executeQuery("SELECT name FROM supplier "); 
                                        rs = stmt.executeQuery("SELECT NOME as nome,EMAIL as email FROM `usuario`");
                                        while(rs.next()) {
                                            out.write("<option value=" + rs.getString("email") + ">" + rs.getString("name") + "</option>");

                                        }
                                        rs.close();
                                        stmt.close();
                                        } 

                                        catch(Exception e) {
                                            System.err.print("Erro!");
                                                           }
                                        %>
                                    </select>

Database class:

    private final String nomeDoBanco;
    private final String login;
    private final String senha;
    private final String host;

    private BancoDeDados() {
        /*
     Trecho de código usado para "Registrar" o driver da JDBC na JVM. 
     Idealmente, é executado apenas uma vez, como é o caso aqui.
         */
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println(e.getMessage());
        }
        /*
     Definições das informações de conexão do banco de dados.
         */
        this.nomeDoBanco = "trabalhodw2";
        this.login = "usuariodw2";
        this.senha = "senhadw2";
        this.host = "localhost";
    }

    public static BancoDeDados getInstance() {
        return instancia;
    }

    /*
     Método usado para retornar uma conexão válida ao nosso banco de dados.
     */
    public Connection conectar() throws SQLException {
        Connection conexao = DriverManager.getConnection("jdbc:mysql://" + host + "/" + nomeDoBanco, login, senha);
        return conexao;
    }
  • Your builder is private and you are giving new. This is just one of the errors, your connection is receiving values that do not exist, since the constructor assignments private BancoDeDados() never invoked. Add the entire class as it seems there are more errors.

  • Use JSTL buddy ;-)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.