0

I am new to jsp and currently working in a simple project.

In that project I need to load values from database to combo box dynamically.

I followed some questions and answers from the web and from stackoverflow also, and found a way to do that.

The only difference is, in that all cases they have used sun.jdbc.odbc.JdbcOdbcDriver, but I am using com.mysql.jdbc.Driver.

When I run my example it does not work, it does not even show the error. Here is my code.

<%@ page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Combo Box</title>
</head>
<body>
    <fieldset>
        <legend>Select One</legend>
        <select id="projectName" class="col-sm-12 selectBox">
            <option value="tttt">-Select-</option>

            <%
                Connection con = null;
                ResultSet rs = null;

                try {
                    Class.forName("com.mysql.jdbc.Driver");
                    con = DriverManager.getConnection(
                            "jdbc:mysql://localhost:3306/new_dbpms", "root",
                            "12345");
                } catch (Exception ex) {
                    out.println("exxx " + ex);
                }
                try {
                    PreparedStatement pst = con
                            .prepareStatement("select projectname from project where branchid=1");
                    //pst.setString(1,uid);
                    rs = pst.executeQuery();
                    while (rs.next()) {
                        String name = rs.getString("name");
            %>
            <option value="<%=name%>"><%=name%></option>
            <%
                }
                } catch (Exception e) {
                    out.print("error: " + e);
                }
            %>

        </select>

    </fieldset>
</body>
</html>

Can you please explain me what is the error here and a way to overcome the issue. Thank you !!

vigamage
  • 1,975
  • 7
  • 48
  • 74

0 Answers0