Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Drop Down boxes from MYSQL

I'm trying to get drop down box with the date of the past 10 days. I'm pulling the information from the food_eaten table and the name of the field is date_eaten. The code below is what i have at the moment and need some pointers in the right direction because the code is not working. Also when i have the code, how do i keep track of what date the user has chosen(1 thru 10)?

<%
     Connection dbconn;
     try
     {
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          try
          {              
               dbconn = DriverManager.getConnection("jdbc:mysql://localhost/nutrition","saundersk","kevin");
               out.println("Connected");
                   
         
          <select name=date>
          <%
         
         
          Statement stmt = dbconn.createStatement();
          ResultSet rs = stmt.executeQuery("select date_eaten from food_eaten");
         
          while (rs.next())
          {
               %>
               <option value="<%= rs.getString("date_eaten") %>"><%= rs.getString("date_eaten") %>
               <%
          }
          rs.close();
          stmt.close();
          con.close();
          %>
         
          </select>
         
          }          
          catch (SQLException s)
          {
               out.println("SQL Error<br>");
          }
     }
     catch (ClassNotFoundException err)
     {
          out.println("Class loading error");
        }
%>
0
sredmusarm
Asked:
sredmusarm
  • 3
  • 2
1 Solution
 
bobbit31Commented:
first, i'd stay away from using names like date b/c it's a reserved word:

<select name=date>

also,
con.close();

should be

dbconn.close();

what exactly isn't working?
0
 
sredmusarmAuthor Commented:
Thanks for the start...The error that apache is giving me is illegal start of expression and then underneath that it gives me the picture of a drop down box?
0
 
bobbit31Commented:
what's the extension of your page? it should be *.jsp

i don't see anything wrong with the above code.

0
 
sredmusarmAuthor Commented:
yeah the extension is .jsp
0
 
sredmusarmAuthor Commented:
yeah the extension is .jsp
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now