jsp code for a drop down box to retrive value from database

jsp code for a drop down box to retrive value from database

my project needs to get the value from database in to the drop down box..... pls give me code for that ..... tan q

View Answers

April 4, 2012 at 3:25 PM

1)login.jsp:

<html>
<script>
function validate(){
var username=document.form.user.value;
var password=document.form.pass.value;
if(username==""){
 alert("Enter Username!");
  return false;
}
if(password==""){
 alert("Enter Password!");
  return false;
}
return true;
}
</script>
<form name="form" method="post" action="check.jsp" onsubmit="javascript:return validate();">
<table>
<tr><td>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td>Select Company: </td><td>
<select name="com">
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login");
           while(rs.next()){
           %>

<option value="<%=rs.getString("company")%>"><%=rs.getString("company")%></option>
<%
           }
%>
</select>
</td></tr>
<tr><td></td><td><input type="submit" value="Login"></td></tr>
</table>
</form>
</html>

2)check.jsp:

<%@page import="java.sql.*"%>
<%
try{
String user=request.getParameter("user");
String pass=request.getParameter("pass");
String com=request.getParameter("com");
 Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'and company='"+com+"'");
           int count=0;
           while(rs.next()){
           count++;
          }
          if(count>0){
           out.println("welcome "+user);
           }
          else{
           response.sendRedirect("login.jsp");
          }
        }
    catch(Exception e){
    System.out.println(e);
}
%>

April 8, 2012 at 10:58 AM

this code is not running exactly... i am getting a blank page while running check.jsp and the value of company is not fetched ..the dropdown is shown empty ... thanks in advance ...









Related Tutorials/Questions & Answers:
jsp code for a drop down box to retrive value from database
jsp code for a drop down box to retrive value from database  my project needs to get the value from database in to the drop down box..... pls give me code for that ..... tan q   1)login.jsp: <html> <script>
retrive the data from access database to drop down list box in jsp
retrive the data from access database to drop down list box in jsp  hai, im new to jsp now im using the jsp along with access database.in table i load all the data's i need to retrive the data from database to dropdown list box
Advertisements
how to retrieve the id value itself from the access database to drop down listbox in jsp
how to retrieve the id value itself from the access database to drop down listbox in jsp  how to retrieves the id which is an int datatype, from access database to drop down list box in jsp...plz send the code for that.....plz
how to import values from database to the drop down box
how to import values from database to the drop down box   hi iam... employee page i kept a drop down box for employee Ids i want all employee IDs will display in the drop down box please help me with the code
jsp login code ... when username , drop down box and password is correct
value is correct.... the drop down box values should be retrieved from database...jsp login code ... when username , drop down box and password is correct ....... the value is retrieved from database into combo box..... but the validation
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
The code for retrieving data from database into Drop Down List.
The code for retrieving data from database into Drop Down List.  <... to MySQL"); PreparedStatement pre = con.prepareStatement("select * from...;% } %> // my code for displaying quantity is below
drop down box - JSP-Servlet
drop down box  when i enter some letter in the input box,the corresponding words of that particular letter must be displayed below as a list from the data base in the same input box as drop down. Thanks&Regards, VijayaBabu.M
store values of drop down list box in database
store values of drop down list box in database  how to store values of drop down list box in oracle database in jsp?I have information inserting form where i have date of birth as drop down list box
dependent drop down box - JSP-Servlet
dependent drop down box  haloo sir Please give me the solution how to extract data from dependent drop down box with page refresh...; window.location.replace("http://localhost:8080/examples/jsp/dependentDropdown.jsp?id="+cid+"&&value
Drop down list from database
Drop down list from database  Hi, Can I know how do we get the drop down list from database? Eg: select country--select state--select district--so... * from country"); while(rs.next()){ %> <option value="<
how can retrive value from combo box in servlet?
how can retrive value from combo box in servlet?  i have a jsp page with combobox. And i want to get value from combox to servlet
Pls provide me jsp code to get values in drop down list from another table's field....
Pls provide me jsp code to get values in drop down list from another table's... in customer registration page and should be shown in drop down box in front end..... pls provide me code.. thanx
insert and retrive image from sql server database in jsp
insert and retrive image from sql server database in jsp  what is the code to insert and retrive an image from sql server database in jsp
retrive image from database using jsp without stream
retrive image from database using jsp without stream  How to retrive image from database using jsp without stream like (inputStream
retrive data from database?
retrive data from database?  hellow i have a database sheet name... from db1 and enter value in text box according there name,rollno and save..... now i want retrive sn,roll no and name and textbox like
By dropdownlist retrive data from database and show in textbox in jsp.
By dropdownlist retrive data from database and show in textbox in jsp.  Hello Sir, I am doing project in jsp.I have to retrive data from database, when I select value from dropdownlist, and that data I want to show in textbox
How to retrieve data from database by using combo box value in jsp? - JSP-Servlet
How to retrieve data from database by using combo box value in jsp?  Hello friend i want use only one jsp page.. but u give 2 pages... I want.... Your code here.. CREATE TABLE "user" ( "name" character varying(100
view data from database using drop down list
view data from database using drop down list  hi i want to view the data from database by selecting a value in a drop down list. for an example drop down list have picture element.when click it select pictures from the database
retrive data from database using jsp in struts?
retrive data from database using jsp in struts?   *search.jsp* <%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <... searchProduct(SearchDTO sdto) { String query="select * from product
retrive the employee details with image from mysql database using jsp servlet
retrive the employee details with image from mysql database using jsp servlet  im doing the web project to retrive the employee profile which i stored in the database using jsp servlet then want to show the result in the next jsp
displaying section in the jsp based on the sected value in drop down - Java Beginners
displaying section in the jsp based on the sected value in drop down   Hi friend, i have one problem in my jsp. i.e i have to display section on the jsp based on the selected value in the drop down list using java script code
How to retrive an inmage from database and displaying it in imgae box - Swing AWT
How to retrive an inmage from database and displaying it in imgae box ...? I want to retrive an image from database and to display it in a small imagebox...(); f.setTitle("Display Image From database"); Image image = f.getToolkit
to update drop down list value when selected from website
to update drop down list value when selected from website  hi help me, i want to insert value into db when i select from a drop down list, this is my code, <div id="age"> Age <select name='NEW'> <option
to update drop down list value when selected from website
to update drop down list value when selected from website  hi help me, i want to insert value into db when i select from a drop down list, this is my code, <div id="age"> Age <select name='NEW'> <option
to update drop down list value when selected from website
to update drop down list value when selected from website  hi help me, i want to insert value into db when i select from a drop down list, this is my code, <div id="age"> Age <select name='NEW'> <option
Drop Down Box
Drop Down Box  In a Drop Down box I want to show the user All the Country In the World. And when he type A-z,then each of the type Show those country which start with those word. Like I For-India
To retrive data from database - Struts
To retrive data from database  How to get values ,when i select a select box in jsp and has to get values in textbox automatically from database? eg... come to jsp page automatically from database
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc...=conn.createStatement(); ResultSet rs=st.executeQuery("select name from
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc...=conn.createStatement(); ResultSet rs=st.executeQuery("select name from
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc...=conn.createStatement(); ResultSet rs=st.executeQuery("select name from
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc...=conn.createStatement(); ResultSet rs=st.executeQuery("select name from
how to set a value of dynamic number of drop down lists on a jsp page and access it value on another jsp page
how to set a value of dynamic number of drop down lists on a jsp page... number of drop down lists(depending upon number of books in that category) on jsp... ,rating2......number of buks in that category(and each drop down list has value
url parameter using retrive data from database in jsp
url parameter using retrive data from database in jsp   the user can... clicks the Preview button, you have to create a dynamic jsp which should read the contents from the db based on the event id. But this jsp url should be a public
url parameter using retrive data from database in jsp
url parameter using retrive data from database in jsp  The user can... clicks the Preview button, you have to create a dynamic jsp which should read the contents from the db based on the event id. But this jsp url should be a public url
retrive data from database
retrive data from database   hi.. i made a application form. it's have attribute s.no,name,roll no and i enter a few records. now i want to view all record not in database access sheet i want to view it at any another
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct........ but in the drop down box ... i need to get the values from backend... value(i.e)company name should match.... pls provide code.... thanx   1
retrieve the data to text fields from database on clicking the value of combo box
retrieve the data to text fields from database on clicking the value of combo box   retrieve the data to text fields from database on clicking the value of combo box . I am not getting it plz help me out .   hi
add text box and select list dynamically and get its value to store it into database using jsp request parameter
add text box and select list dynamically and get its value to store it into database using jsp request parameter  its very helpful when you have only dynamically added text field but want code to retrive value of dynamically
loading value into combo box by selecting value from other combo box - JSP-Servlet
loading value into combo box by selecting value from other combo box  ... is that as i select state from state_combo_box,then the next combo box is dynamically... table "state" it contains state and code. each state table contain districts
store and retrive image from the database
store and retrive image from the database  please provide me... to store and retreive images from sql database using sql commands -how to store and retreive images from sql database using asp.net/c# thanks in advance
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database... of selecting value from autocomplete textbox using jquery in jsp from mysql database. Kindly send me the complete code . Thnx
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database. ... but was unable to find out exact way to fullfill the solution of selecting value from autocomplete textbox using jquery in jsp from mysql database. Kindly send me
JSP Dependent Drop Down Menu
JSP Dependent Drop Down Menu  Hey Guy/Gals! I need someone help to guide me in creating a drop down menu, where the first menu affects the second...; The given code will help you to create a dependent dropdown box. 1
How to send the data selected from drop down menu from html page to sql 2005 database.
How to send the data selected from drop down menu from html page to sql 2005 database.  Dear Sir, If I want to save the information provided by user from html drop down menu such as check-in date for hotel reservation
Retrive data from database and perform binary tree operations on that data in jsp or java
Retrive data from database and perform binary tree operations on that data in jsp or java  To develop code for MLM project. I want to retrieve data from database dynamically and perform operations on that. Just like calculate
Drop down and radio button value on edit action
Drop down and radio button value on edit action  HI, I have a title field and a payment type field for title i have used drop down with values... i get the value from the database for title and radio button selected
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct... in dropdown box.... so when i login i all the three username,password and dropdown box value(i.e)company name should match.... pls provide code.... thanx   
jsp drop down-- select Option
jsp drop down-- select Option  how to get drop down populated...) in database and try the following code:ADS_TO_REPLACE_1 <%@page import="java.sql.... = stmt.executeQuery("Select * from country"); while(rs.next()){ %> <option value
how to make drop down list in JSF & fetch data Item from database
how to make drop down list in JSF & fetch data Item from database  how to make drop down list in JSF & fetch data Item from database

Ads