Results 1 to 2 of 2
  1. #1
    SREEMANTH143 is offline Member
    Join Date
    Sep 2015
    Posts
    1
    Rep Power
    0

    Default Problem with populating DropDownList with data from DataBase

    Hi Guys,
    I am new to JAVA.I am trying to populate my DropDownList with column data from table in Oracle database I have created.But the data is not appearing
    in the DropDown list of JSP.I am posting the code snippets and screen shots of my project.Please help me so that I can move foward.

    My JSP(RENT.JSP)
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

    <%@ page import="java.sql.*" %>
    <%ResultSet resultset =null;%>
    <html>
    <head>
    <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    $( "#date" ).datepicker();
    });
    </script>
    </head>
    </head>
    <body>
    <h1>CHOOSE YOUR CAR</h1>
    <form name="carselect">
    <select name="CAR">
    <c:forEach items="${Data}" var="d">
    <option value="${d.id}">${d.name}</option>
    </c:forEach>
    </select>
    </form>

    <h4><a href="HOME.jsp">HOME</a></h4>
    </body>
    </html>



    My Servlet(Testdb.java)
    package com.sigma.carrental.servlet;


    import java.io.IOException;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;

    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class Testdb extends HttpServlet {
    private static final long serialVersionUID = 1L;


    public Testdb() {
    super();

    }


    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }



    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    Connection con=null;
    ResultSet rs=null;

    try {
    Class.forName("oracle.jdbc.OracleDriver");
    } catch (ClassNotFoundException e) {

    System.out.println("NO DRIVER");
    }

    try {
    con=DriverManager.getConnection("jdbc:oracle:thin: @localhost:1521:XE","SYSTEM","ORACLE");
    } catch (SQLException e) {
    System.out.println("conncetion failed");;
    }


    try{
    Statement st=con.createStatement();
    rs=st.executeQuery("select * from RENTACAR.CARLIST");
    }
    catch(SQLException e)
    {
    System.out.println("statement cretion failed");
    }



    List a1=new ArrayList();



    try {
    while(rs.next())
    {
    try {
    a1.add(rs.getString("CARNAME"));
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    request.setAttribute("Data", a1);
    request.getRequestDispatcher("/WEB-INF/RENT.jsp").forward(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    }


    MY FILE STRUCTURE
    Problem with populating DropDownList with data from DataBase-structure.png


    WEB.XML
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>CARRENTAL</display-name>
    <welcome-file-list>
    <welcome-file>HOME.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
    <servlet-name>Testdb</servlet-name>
    <servlet-class>com.sigma.carrental.servlet.Testdb</servlet-class>
    </servlet>


    <servlet-mapping>
    <servlet-name>Testdb</servlet-name>
    <url-pattern>/jasti</url-pattern>
    </servlet-mapping>
    Last edited by SREEMANTH143; 09-08-2015 at 03:52 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Problem with populating DropDownList with data from DataBase

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. best practice populating ui from database
    By keuninkske in forum New To Java
    Replies: 0
    Last Post: 12-22-2013, 04:02 PM
  2. Replies: 0
    Last Post: 08-14-2013, 04:12 PM
  3. populating jtable from database
    By java_begin in forum New To Java
    Replies: 1
    Last Post: 01-16-2013, 11:56 PM
  4. Populating Jtable from database - better way?
    By madhura2212 in forum AWT / Swing
    Replies: 5
    Last Post: 10-05-2010, 02:04 PM
  5. Populating a drop down list from a database
    By matpj in forum New To Java
    Replies: 0
    Last Post: 01-19-2009, 12:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •