Popular comboBox through a query in the database

0

I know I'm doing the wrong way to populate my comboBox, I'm doing this on the client side rather than doing server side is that java is not my beach.

I'm trying to pop up my comboBox as follows: But from the error can not find symbol class connect just below the try in the Connection connection line = new Database.Connect ();

 <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;
    }
    
asked by anonymous 12.12.2015 / 00:34

0 answers