Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Combobox-java servlet

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
here i have 3 files

admin.java IN this file i want to retrieve data from database and should be appeared in combobox

when i click on admin.jsp and it is give error(it is catch(Exceptione))

it is not enter in the select * from Record

please help me and give correct code








admin.java

import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

import java.util.ArrayList;


public class admin extends HttpServlet{

private ServletConfig config;

public void init(ServletConfig config)

throws ServletException{

this.config=config;

}

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

PrintWriter out = response.getWriter();

response.setContentType("text/html");



Connection connection;
ResultSet rs;
Statement statement;

System.out.println("hi");




ArrayList deptlist=new ArrayList();




try {




Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

connection = DriverManager.getConnection("jdbc dbc:Record");

statement=connection.createStatement();

String sql = "Select NI from Record order by 1 asc";

rs = statement.executeQuery(sql);




while(rs.next())
{

String NI= rs.getString("NI");

out.println(NI);

System.out.println(NI);

deptlist.add(NI);



}

RequestDispatcher dispatcher= getServletContext().getRequestDispatcher("/admin.jsp");
request.setAttribute("NI",deptlist);
dispatcher.forward(request, response);

}




catch(Exception e1)
{
out.println("error");
e1.printStackTrace();
}




}




}



admin1.java
public class admin1
{
private String ni, city, purpose ,dsn, sn, pa, sa, year;





public admin1()
{

sn ="";
year ="";
dsn="";
ni="";
city="";
purpose="";
pa="";
sa="";

}




public admin1(String sn, String year, String dsn, String ni, String city, String purpose, String sa, String pa)
{

this.sn = sn;
this.year = year;
this.dsn = dsn;
this.ni = ni;
this.city= city;
this.purpose = purpose;
this.sa = sa;
this.pa = pa;

}





public void setSN(String n)
{
sn=n;
}
public void setYear(String y)
{
year=y;
}
public void setDSN(String d)
{
dsn=d;
}
public void setNI(String na)
{
ni=na;
}

public void setCity(String c)
{
city=c;
}
public void setPurpose(String p)
{
purpose=p;
}
public void setSA(String a)
{
sa=a;
}
public void setPA(String pe)
{
pa=pe;
}





public String getSN()
{
return sn;
}

public String getYear()
{
return year;
}

public String getDSN()
{
return dsn;
}

public String getNI()
{
return ni;
}

public String getCity()
{
return city;
}

public String getPurpose()
{
return purpose;
}

public String getSA()
{
return sa;
}
public String getPA()
{
return pa;
}





}


admin.jsp

<%@ page language="java" %>
<%@ page import ="java.sql.*;"%>



<html>
<head>
<title>Login Page</title>

</head>
<body bgcolor="teal" >

<h1><center><b><font color="yellow">Login</h1></center><a href="AuthenticLogin.jsp"><font color="yellow">Sign Out</font></a></font></b></font></b>


<hr size="7" color="yellow">
<br>



<form name="frm" action="admin" method="Post" >

<%@ include file="left.jsp"%>

<font color="Yellow" size="3">

<select property="select" name="select" onchange="frm.submit();">
<options collection="deptlist" property="select" key="NI" />

<option>select university</option>



</select><br>

<br>

<b>Sanction No:                  </b><input type="text" name="sno" value=""/><br>
<br>

<b>Year:                        
     </b><input type="text" name="year" value=""/><br>

<br>
<b>Date of Sanction No:    </b><input type="text" name="dsn" value=""/><br>
<br>
<b>Name of Institute:         </b><input type="text" name="ni" value="" size="50"/><br>
<br>
<b>City:                    
          </b><input type="text" name="city" value="" size="50"/><br>
<br>
<b>Purpose:                         </b><input type="text" name="purpose" value="" size="75"/><br>
<br>
<b>Sanction Amount:          </b><input type="text" name="sa" value=""/><br>
<br>
<b>Pending Amount:           </b><input type="text" name="pa" value=""/><br>
<br>
<br>

     <input type="submit" name="Update" value="Update" />
     <input type="submit" name="Delete" value="Delete" />

     <input type="reset" name="cancel" value="Cancel" />


<br>



</font>
</form>
</body>
</html>
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please don't post the same question in more than one topic.
 
You can't have everything. Where would you put it?
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
    Bookmark Topic Watch Topic
  • New Topic