*
The moose likes Servlets and the fly likes Combobox-java servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

Combobox-java servlet

lathainses muthu
Greenhorn

Joined: Aug 06, 2008
Posts: 5
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>
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Please don't post the same question in more than one topic.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Combobox-java servlet