0 Replies - 681 Views - Last Post: 07 September 2015 - 07:53 PM

#1 SREEMANTH   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-September 15

Problem with populating DropDownList with data from DataBase

Posted 07 September 2015 - 07:53 PM

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 forward.


My File structure
Posted Image



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 {

}

}



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>



Is This A Good Question/Topic? 0
  • +

Page 1 of 1