Home Answers Viewqa JSP-Servlet view data from database using drop down list

 
 


rasanga ratnayake
view data from database using drop down list
5 Answer(s)      a year and 10 months ago
Posted in : JSP-Servlet

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

View Answers

July 18, 2011 at 12:59 PM


 <%@page import="java.sql.*"%>
<html>
<form method="post" action="picture.jsp">
      <select name='pic'>  
      <option value="none">Select</option>  
      <%
      Class.forName("com.mysql.jdbc.Driver").newInstance();  
      Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
      Statement stmt = con.createStatement();  
      ResultSet rs = stmt.executeQuery("Select * from image");
      while(rs.next()){
          %>
          <option value="<%=rs.getString("imagename")%>"><%=rs.getString("imagename")%></option>
           <%
      }
     %>
      </select>
      <input type="submit" value="Submit">
      </form>
      </html>

July 18, 2011 at 1:00 PM


continue......

picture.jsp:

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%
String iname=request.getParameter("pic");  
 try{
     InputStream sImage;

 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 Statement st=con.createStatement();
      ResultSet rs=st.executeQuery("SELECT images FROM image WHERE imagename ='"+iname+"'");
      if(rs.next()){
      byte[] bytearray = new byte[1048576];
      int size=0;
      sImage = rs.getBinaryStream(1);
      response.reset();
      response.setContentType("image/jpeg");
      while((size=sImage.read(bytearray))!= -1 ){
      response.getOutputStream().write(bytearray,0,size);
   }
}
 }
 catch(Exception e){
     System.out.println(e);
 }
 %>

July 18, 2011 at 1:00 PM


continue......

picture.jsp:

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%
String iname=request.getParameter("pic");  
 try{
     InputStream sImage;

 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 Statement st=con.createStatement();
      ResultSet rs=st.executeQuery("SELECT images FROM image WHERE imagename ='"+iname+"'");
      if(rs.next()){
      byte[] bytearray = new byte[1048576];
      int size=0;
      sImage = rs.getBinaryStream(1);
      response.reset();
      response.setContentType("image/jpeg");
      while((size=sImage.read(bytearray))!= -1 ){
      response.getOutputStream().write(bytearray,0,size);
   }
}
 }
 catch(Exception e){
     System.out.println(e);
 }
 %>

July 18, 2011 at 1:02 PM


Try the following code:

1)selectpicture.jsp:

 <%@page import="java.sql.*"%>
<html>
<form method="post" action="picture.jsp">
      <select name='pic'>  
      <option value="none">Select</option>  
      <%
      Class.forName("com.mysql.jdbc.Driver").newInstance();  
      Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
      Statement stmt = con.createStatement();  
      ResultSet rs = stmt.executeQuery("Select * from image");
      while(rs.next()){
          %>
          <option value="<%=rs.getString("imagename")%>"><%=rs.getString("imagename")%></option>
           <%
      }
     %>
      </select>
      <input type="submit" value="Submit">
      </form>
      </html>

2)picture.jsp:

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%
String iname=request.getParameter("pic");  
 try{
     InputStream sImage;

 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 Statement st=con.createStatement();
      ResultSet rs=st.executeQuery("SELECT images FROM image WHERE imagename ='"+iname+"'");
      if(rs.next()){
      byte[] bytearray = new byte[1048576];
      int size=0;
      sImage = rs.getBinaryStream(1);
      response.reset();
      response.setContentType("image/jpeg");
      while((size=sImage.read(bytearray))!= -1 ){
      response.getOutputStream().write(bytearray,0,size);
   }
}
 }
 catch(Exception e){
     System.out.println(e);
 }
 %>

July 18, 2011 at 3:04 PM


thanks a lot :)









Related Pages:
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 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
Dependent drop down list
dependent drop down list is used my code is successful but when i select class from first drop down list all the data get lossed means the value entered in fields before drop down list get blank.what can i do for this? This is the code
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="<
Dependant & dynamic drop down list
be in this or AJAX forum. I have one dynamic drop down list from data base (working... on the values selected by user in first drop down list. How to achieve this ?   ...`));   This will select only ONE row (country) from first drop down. In my case
dynamic drop down list
dynamic drop down list  I want to create 2 drop down list, where it takes value from database and the two list are dependent..means if I select a particular value from one the other list is developed accordingly..depending
how to retreive data dynamically from mysql to drop down list
how to retreive data dynamically from mysql to drop down list   sir... fron end using jsp , after storing the data successfully .i want to retrieve the data of a particular column in a table into drop down list dynamically
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 and postgresql as data base syntax which i m using is like:- java class
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 and postgresql as data base syntax which i m using is like:- java class
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 and postgresql as data base syntax which i m using is like:- java class
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 and postgresql as data base syntax which i m using is like:- java class
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
How to insert multiple drop down list data in single column in sql database using servlet
How to insert multiple drop down list data in single column in sql database using servlet  i want to insert date of birth of user by using separate drop down list box for year,month and day into dateofbirth column in sql server
Get values in drop down list
Get values in drop down list  Pls provide me jsp code to get values in drop down list from another table's field. my project has customer... in drop down box in front end..... pls provide me code.. thanx
dynamic drop down list box - Java Beginners
dynamic drop down list box  hi all , I want to dynamically populate a drop down box from an sql query in a servlet program, using only html... servlet comes under server side code. if not using servlet store the all data
Login With Drop Down
using the drop down box and the Username and passwords must match with the Database...Login With Drop Down   Hi all, I am doing a project using JSP. My... a drop down list consisting of Customs and Accounts. I have user accounts of both
Excel Cell Drop Down List
Excel Cell Drop Down List In this section, you will learn how to validate data entered in a cell and provide a drop down list of possible values to the user... the following error message : You can select the value from the drop down
data should not repeat in the drop down list when it is loading dynamically from database
the whole department field from the data base (i.e in the drop down list...data should not repeat in the drop down list when it is loading dynamically... be included in the drop down list. 1)selDept.jsp: <%@page import
data should not repeat in the drop down list when it is loading dynamically from database
data should not repeat in the drop down list when it is loading dynamically from database  selDept.jsp <%@page import="java.sql.*"%>... the data dynamically for database but my problem is in the list the same
data should not repeat in the drop down list when it is loading dynamically from database
data should not repeat in the drop down list when it is loading dynamically from database  selDept.jsp <%@page import="java.sql.*"%> <..._NO`) ); the data is coming from
Drop Down
Drop Down  How to insert date into database using dropdown like facebook
drop down
drop down  how can i add data from choice/dropdown component of java awt to myaql table
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
Dependant & dynamic drop down list - Follow up
Dependant & dynamic drop down list - Follow up  Thanks for your answer. As per your answer This will select only ONE row (country) from first drop down. In my case user can choose more than one row , which is then sent to next
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...=mysql_query("select * from age order by Age_Desc"); while($row_list=mysql_fetch
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...=mysql_query("select * from age order by Age_Desc"); while($row_list=mysql_fetch
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...=mysql_query("select * from age order by Age_Desc"); while($row_list=mysql_fetch
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
Login With Drop Down, Having Departments in different table
to login when I select department from the drop down list. Since I cannot populate... the HTML page in such a way the I have a drop down list consisting of Customs... is to select the department from the drop down box and then login to the page. I
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... by user from html drop down menu such as check-in date for hotel reservation system ,how can I save these data in database and how to retrieve later .Thanks
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
drop down list in Struts
drop down list in Struts  How to create a drop down list in Struts
Select tag to fetch data from oracle database
of a student and when regnno is selected from the drop down list by a user... the drop down list then one box will appear where user will type the address then he...Select tag to fetch data from oracle database  I created a select box
Drop Down reload in IE
Drop Down reload in IE  Hi i was using two drop down box..One for Displaying date followed by another for Dispalying Month..If i Select/Change Month from the 2nd drop down then the 1st drop down ( which is date) automatically
Select functionality of drop down list - Struts
(in struts application) in which if user select HIDE from the drop down list... have Drop down list having element Test1,Test2,Test3,HIDE and one Text msg box for entering Age,Now if user select "HIDE" from drop-down list the below text
Copying and Moving data using drag and drop
Copying and Moving data using drag and drop: You can drag and drop the data from list to dataGrid using different data formats in this example. When you...; <s:Label text="Drag and drop data from List to datagrid"
validation for drop down list
validation for drop down list  Hi all I have a form, it contain 12 drop down list. Each drop down has 1 to 5 values,i need to validate this form. the following condition should be true. 1.you can choose only 3 times 5 value. 2
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... pages..... when i insert data in company registration .. it ll have company id
how to store multiple values from drop down in database where i am using java struts 1.3
how to store multiple values from drop down in database where i am using java struts 1.3  hii, i am coding a form where i need a keyskills attribute where i have to select multiple keyskills. but it is taking only one valuee.. i
creation of drop down menu using ajax in java - Ajax
creation of drop down menu using ajax in java  Hi, Here I want to create a drop down menu using ajax in ofbiz framework. I want to fetch the data from database.I got examples using asp.net and php but I am not getting
Drop-down text selection in jsp/html
Drop-down text selection in jsp/html  Hi, I am trying to create JSP page where I have two drop-downs. There are two-sets of data - First set.... Now the first dropdown will have all the values. The second drop-down depends upon
how to add data dynamically from database into a dropdown list in a jsp
how to add data dynamically from database into a dropdown list in a jsp ... of the persons who work in that department.The values into the drop down list should... and department fields also.I have a create an jsp page in which there should 2 drop down
Ajax drop down and textbox
Ajax drop down and textbox  hie frnds I have a dropdown menu in the 3... menu consisting of options 1,2,3. When the user select any option from...;And one more thing how to insert to the database dynamically
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..., we have used following database tables: 1)book CREATE TABLE `book
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..... While the edit form is being displayed it gets all the values from the database
Add/Remove Rows Dynamically with drop down list in html table using php
Add/Remove Rows Dynamically with drop down list in html table using php  Here Is My Code. I want to give and get the id of drop down list. Can Anyone..."); $result=mysql_query("select * from test"); while($row
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 Get Data Into Dropdown list From Database
data from the database and set it into the dropdown list in JSP using MySQL...JSP Get Data Into Dropdown list From Database In this section we will discuss.... This tutorial explains you that how to fetch data from database and set
view
view  hi iam writing some struts application by using dyanafalidator form in place of actionform bean classes i can enter data by using some jsp file and it will insert to database by using business logic. now my requirement
How to pass parameter through drop down list using session management in jsp??
How to pass parameter through drop down list using session management in jsp??  How to pass parameter through drop down list in the URL and access it on same jsp page using session management

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.