retrieve the value from database into dropdown list using JDBC SQL 2005

Ads

 
 

Share on Google+Share on Google+

Sudha Surendhiran
retrieve the value from database into dropdown list using JDBC SQL 2005
2 Answer(s)      5 years and 6 months ago
Posted in : SQL

How to retrieve the value from database into dropdown list using JDBC & SQL 2005?

Ads
View Answers

March 14, 2012 at 12:35 PM


JSP Code:

Create table country(country_id,country) in database and try the following code:

<[email protected] import="java.sql.*"%>
<html>
<form name="form" method="post" >
<b>Select a country:</b>&nbsp;</td>
<select name="sel"><option value=""><---Select---></option>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
String connectionURL = "jdbc:mysql://localhost:3306/test";;
Connection connection= DriverManager.getConnection(connectionURL, "root", "root");
PreparedStatement psmnt = connection.prepareStatement("select * from country ");
ResultSet results = psmnt.executeQuery();
while(results.next()){
String name = results.getString(2);
String id = results.getString(1);
%><option value="<%= name %>">
<% out.println(name); %>
</option>
<%} results.close(); psmnt.close(); %>
</select><br>
<input type="submit" value="Submit"/><br>

</form>
<%String option=request.getParameter("sel");
if(option==null){
}
else{%>
<input type="text" value="<%=option%>">
<%
}
%>
</html>


March 14, 2012 at 12:50 PM


Java Code:

import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class ComboExample {
    ComboExample() {
        JFrame f = new JFrame();
        f.getContentPane().setLayout(null);
        final JComboBox combo = new JComboBox();

            try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root","root");
            Statement st = connect.createStatement();
            ResultSet rs = st.executeQuery("Select name from data");
                        while (rs.next()) {
                        combo.addItem(rs.getString("name"));

            }
            } catch (Exception ex) {
                }

        combo.setBounds(20, 50, 150, 20);
        f.add(combo);

        f.setSize(400, 200);
        f.setVisible(true);
    }
    public static void main(String[] args) {
        ComboExample c = new ComboExample();
    }
}

Ads









Related Tutorials/Questions & Answers:
3 dropdown list from the database using JSP
3 dropdown list from the database using JSP  Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
how to load value in dropdown list after selecting value from first dropdown list using javascript
how to load value in dropdown list after selecting value from first dropdown list using javascript  how to load value in dropdown list after selecting value from first dropdown list using javascript
Advertisements
Database connection sql server 2005 - JDBC
Database connection sql server 2005  Hi all i am developing an application in struts and i need to connect database for that application using sql server 2005.. can anyone tell me how to make database connection ..plz help me
Dropdown code to retrieve result from oracle database
that will retrieve values from the database into dropdown. As the user choose any option...Dropdown code to retrieve result from oracle database  Hi Friends, I... retrieve the result from Oracle database.We have procedures created already.Just
Retrieve data from database by using sql tag of JSTL SQL library
Retrieve data from database by using sql tag of JSTL SQL library... we will see how retrieve data from database using sql query given by user... named 'employee_master' in same database by the sql query given below
How to search the table name in MS SQL Database 2005 from application
How to search the table name in MS SQL Database 2005 from application  How to search the table name in MS SQL Database 2005 from application from our helpdesk application? application might be in html
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how to retrieve data from database using combobox value without using request.getParameter in jsp  Answer pl
retrieve related data from database using jsp and mysql
retrieve related data from database using jsp and mysql  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list. if we change a value in a dropdown its related value must
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... fetching of data into the dropdown list in JSP using Eclipse IDE and the Tomcat 7
Retrieve value of radio button from database to form
Retrieve value of radio button from database to form  var gn=document.getElementsByName("empg"); //empg is name of radio input type. for(var i=0;i
help to select a value from the dropdown list
help to select a value from the dropdown list  I have a html file... from the drop down list created in a div and put it in the textbox kim... <input type="text" size="30" name="inputString" value="" id="inputString
Using C# DataGridView to insert record into Microsoft SQL Server 2005 database - SQL
Using C# DataGridView to insert record into Microsoft SQL Server 2005 database  Dear Sir, I am new to Microsoft SQL Server 2005. Currently, i'm creating a sales database system using C# and Microsoft SQL Server 2005. I had
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... system ,how can I save these data in database and how to retrieve later .Thanks
retrieve data from database using jsf
retrieve data from database using jsf  Hello I want an example of source code to retrieve data from database i have a database (oracle) name as db1...),, name ,and city I want after enter value in textbox according idauthor i retrieve
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?  ...; } function showEmp(emp_value) { if(document.getElementById("emp_id").value...="+emp_value xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP  as i said i want to create 3 drop dropdown list each depend on the other and get the options from
create a xml from sql server 2005 - XML
create a xml from sql server 2005  hello Dear, i want to know how we create a xml file which retrieve data from Sql server 2005 using java. i am briefing my problem as follows. let i have a table in sql server 2005
Populate dropdown menu from database using jsp and servlet
Populate dropdown menu from database using jsp and servlet  please i need code to populate dropdown menu from mysql database using jsp and servlet. thanks
Retrieve values from database using views
Retrieve values from database using views  hi......... I have a huge database so i have created views in database where i am selecting only the columns which are required. As my front end is java swings i want to retrieve data
Retriving value from dropdown list nad disply it in other page
Retriving value from dropdown list nad disply it in other page  Hello, I have a dropdownbox on my webpage and a map which contains a marker... of the selected value from the dropdown list and dispaly it to on the next page. i
retrieve value from database on the basis of maximum id number
retrieve value from database on the basis of maximum id number  hi, i want to retrieve value of maximum id number from the database and show that value in jTextField.when the user clicks on the button that maximum id number
<img src=""> using retrieve image from database using jsp
using retrieve image from database using jsp  how to <img src="" > tag using retrieve image from database and display in jsp
To retrieve image from SQL Server Database - Java Server Faces Questions
To retrieve image from SQL Server Database  Sir/Madam, I am trying to retrieve image from SQL Server 2000 database in Visual Web JSF Page using... or in Image Component. please help me in retrieving and displaying image from SQL Server
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... getting data into textarea from database table by clicking on the button
Retrieve database from the table dynamically in jsp from oracle using servlet
Retrieve database from the table dynamically in jsp from oracle using servlet  Sir, I have created a table in oracle using eclipse, and added few... using java servlet from the database in the jsp page
connect sql server 2005 using php
connect sql server 2005 using php  how to connect sql server 2005 using php program. how mssql_connect will work
How to insert image in sql database from user using servlet
How to insert image in sql database from user using servlet  pls tell me accept image from user and insert image in sql server 2005 database using servlet and jsp
how to connect SQL Server 2005 using php
how to connect SQL Server 2005 using php  i need to connect SQL Server 2005 using php. how can i connect . how to use mssql_connect function
jsp- database dependent dropdown list
jsp- database dependent dropdown list   i want 2 dropdown list 1- CLASS 2-SECTION both are should come from database. and if i select a class suppose class a the corresponding section dropdown list should retrieve the section
how to store and retrieve images int and from the database using php
how to store and retrieve images int and from the database using php  please anyone can help me in storing the images and retrieve it back from the Mysql database using php
populating textbox value from the database using onchange function,
populating textbox value from the database using onchange function,  ... selecting from dropdownlist. i have a form in jsp n I created the dropdown list dynamically from the database(mysql). after selecting the value from the dropd