954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

find a solution to display data in dropdown from database using java

hi all,
i want to display some data in dropdown from database using java.please send the code

muraliinfy04
Newbie Poster
1 post since May 2008
Reputation Points: 10
Solved Threads: 0
 
public class TheCode {
    public void getDataFromDB(Dropdown b) {
        b.populateList();
    }
}
masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

hi friend,
first establish the connection
example:
step 1: import sql package(import java.sql.*;)
step 2: initiate driver:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
step 3:creat connection:
Connection conn = DriverManager.getConnection(url,username,password);
url --> "jdbc:odbc:DSN Name"
DSN(data source name).
user -->user name of the server
password -->password of the server
this 3 parameters are String.
step 4:create statement:
Statement stmt = conn.createStatement();
step 5:use result set to access the records in the table
ResultSet rset = stmt.executeQuery("SELECT * FROM Table_Nmae");
step 6:this code is used to display the value of the Table_Name from first to last row
while(rset.next())
System.out.println(rset.getString(1));
getString(1) -->means first column(field) value of each row

this are the example for list the database values.if you want to list it as dropdown by using "JComboBox" class its in java swing(jdk1.5).
example:
JComboBox object_Name = new JComboBox();
we use object_Name.addItem(rset.getString(1)); to System.out.println(rset.getString(1));

try it...

freshface001
Newbie Poster
18 posts since Apr 2008
Reputation Points: 10
Solved Threads: 2
 

i have problem i want retriving value in database in dropdownlist and i want insert the next same dropdownlist plz check where iam wrong
using System.Data.SqlClient;

public partial class Default4 : System.Web.UI.Page
{
string brandno,s1 ,s2,pno ;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = ConnectionClass.getconnection();
SqlCommand cmd = new SqlCommand(

Ashutosh shukla
Newbie Poster
1 post since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You