binding jComboBox to mysql database

binding jComboBox to mysql database

View Answers

January 10, 2009 at 12:52 AM

Hi friend,

code to help in solving the problem :

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

public class JComboBoxExample extends JPanel {
JLabel jlbPicture;

public JComboBoxExample() {
String[] comboTypes = { "Numbers", "Alphabets", "Symbols"};

Vector<Object> vector = new Vector<Object>();
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "userdetails";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db, user, pass);
try{
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM userform");
while (res.next()) {
vector.add(res.getString("username"));


}
con.close();
}
catch (SQLException s){
System.out.println("SQL code does not execute.");
}
}
catch (Exception e){
e.printStackTrace();
}


JComboBox comboTypesList = new JComboBox(vector);
comboTypesList.setSelectedIndex(2);
comboTypesList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox jcmbType = (JComboBox)e.getSource();
String cmbType = (String)jcmbType.getSelectedItem();
jlbPicture.setIcon(new ImageIcon(""+cmbType.trim().toLowerCase() + ".jpg"));
}
});

// Set up the picture
jlbPicture = new JLabel(new ImageIcon("" +
comboTypes[comboTypesList.getSelectedIndex()] +
".jpg"));
jlbPicture.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));

jlbPicture.setPreferredSize(new Dimension(177, 122+10));

// Layout the demo
setLayout(new BorderLayout());
add(comboTypesList, BorderLayout.NORTH);
add(jlbPicture, BorderLayout.SOUTH);
setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
}

public static void main(String s[]) {
JFrame frame = new JFrame("JComboBox Usage Demo");

frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});

frame.setContentPane(new JComboBoxExample());
frame.pack();
frame.setVisible(true);
}
}


Thanks









Related Tutorials/Questions & Answers:
binding jComboBox to mysql database - Swing AWT
binding jComboBox to mysql database  I am using netbeans 6.5 How to populate jComboBox with data of specific column of mysql database table? I... = null; String url = "jdbc:mysql://localhost:3306/"; String db
jComboBox with database
jComboBox with database  Hello friends, I have created three JComboBoxes. first two of them get list from string. However I select these two... my database. But in my code its only get data from first item which
Advertisements
Help on database and JComboBox
Help on database and JComboBox  I want to select from the JComboBox and when click onto the "search" button, the selected category (example "new york... the things from database
Database values in JComboBox
Database values in JComboBox In this section, you will learn how to display values in JComboBox from database. For this, we have allowed the user to enter... the database will get displayed on the ComboBox. If there will be  no data
Link To Database with JComboBox - Java Beginners
Link To Database with JComboBox  sir As ur Source Code i have Load course names from Access Database in to JComboBox but now I want to do ,when i select Course name from Jcombobox i want to display appropriate records relate
JComboBox
JComboBox  I have jcombobox. In which tha values are loaded from MySql Database. My problem is that i want to load content of the jtable whenever i change the selected item. Please some one help me to do this. Thank you
How to store JComboBox item into database
How to store JComboBox item into database   import... DefaultComboBoxModel(labels); final JPanel TypeTF = new JPanel(); JComboBox comboBox1 = new JComboBox(model); comboBox1.setEditable(false
JComboBox
have jcombobox on Jframe form of IDE. In which the values are to be loaded from MySql Database. My problem is that i want to load content of the jtable whenever i change the selected item in JComboBox. Thank you. (adsbygoogle
MYSQL Database
MYSQL Database  Can any one brief me about how to use MYSQL Database to store the create new database, create tables. Thanks.   Hi, the MySQL database server is most popular database server and if you want to know
JComboBox
JComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according
jComboBox
jComboBox  I want to change the index of one jComboBox according to the selected index of another jComboBox. I can do it.Also the user should have the ability to select or change the index of the second combobox according
jcombobox
jcombobox  hi i have developed a form and i have jcombobox in which data is retrieved from ms access but the problem is that if we pressed the down key the last 5 data are not showed only the other data can be pressed
Jcombobox
Jcombobox  Hii, I am doing my final year project and i am using java swing as a front end.I have used Jcombobox for displaying my on bluetooth devices and i also made a refresh button.when i click on the refresh button i
Add Items in JComboBox from Access Database - Java Beginners
Add Items in JComboBox from Access Database  Heelo Sir I want To add ittem in JComboBox which is stored in Access Database. plz Help Me Sir Database Column name -Course Items -MBA,MCA,MBA IT,MBA FINANCE I want Load Database
update mysql database
update mysql database  update mysql database
How to store JComboBox selected Item into Ms Access Database - Java Beginners
How to store JComboBox selected Item into Ms Access Database  How to store JComboBox selected Item into Ms Access Database.  Hi Friend..."); f.getContentPane().setLayout(null); JLabel lbl1=new JLabel("Branch"); final JComboBox jc
Load Coursenames from MS Acess Database to JComboBox - Java Beginners
Load Coursenames from MS Acess Database to JComboBox  Hello sir, I want to Load/add Course names which stored in Ms Acess 2007 Database, plz help..."); final JComboBox jc=new JComboBox(); try{ Class.forName
Database - mysql - SQL
Database - mysql size limit  What is the size limit for any mysql database
How to save JCombobox Selected Item in to Access Database - Java Beginners
How to save JCombobox Selected Item in to Access Database  How to save JCombobox Selected Item in to Access Database  Hi Friend, Try...().setLayout(null); JLabel lbl1=new JLabel("Branch"); final JComboBox jc=new
insert images into a Mysql database
insert images into a Mysql database  How can I insert images into a Mysql database
XML parsing to Mysql database
XML parsing to Mysql database  Can someone please post the code for parsing an XML file into Mysql database using SAX
Create Database and tables in MySQL
and tables in MySQL Database? Explain me step-by-step as I am beginner in MySQL. Thanks   Hi, First of all you have to connect to MySQL database through command line tool. Connecting to MySQL Database: mysql -uroot -p Here
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using mysql
what is the mysql in the database using php
what is the mysql in the database using php  what is the mysql in the database using php  Please visit the following link: PHP Database
what is the mysql in the database using php
what is the mysql in the database using php  what is the mysql in the database using php  Please visit the following link: PHP Database
Connecting to MYSQL Database in Java
Connecting to MYSQL Database in Java  I've tried executing the code...("MySQL Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost/"; String dbName = "textbook"; String driver
MySql database - SQL
MySql database  hello sir, i am trying to write a code which should... to retrieve the data from Ms-access then you create a database , table and create a connection with this. Then you retrieve the data from the database. Thanks
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access  import javax.swing.*; import java.awt.*; import java.sql.*; class Comboo extends JFrame { JComboBox jcb; Connection con
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access  import javax.swing.*; import java.awt.*; import java.sql.*; class Comboo extends JFrame { JComboBox jcb; Connection con
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access  import javax.swing.*; import java.awt.*; import java.sql.*; class Comboo extends JFrame { JComboBox jcb; Connection con
Setup MySQL Database
Setup MySQL Database      ... into MySQL database. Table created here will be used in sample application.../mysql/mysql5/Installing-MySQL-on-Windows.shtml Creating Database : You can create
Submit button to MySQL database?
Submit button to MySQL database?  Need help linking html code to mysql database <html> <head> <meta http-equiv="Content-Type...").newInstance(); Connection connection = DriverManager.getConnection("jdbc:mysql
Submit button to MySQL database?
Submit button to MySQL database?  Need help linking html code to mysql database <html> <head> <meta http-equiv="Content-Type...").newInstance(); Connection connection = DriverManager.getConnection("jdbc:mysql
Backup MySQL Database - JSP-Servlet
Backup MySQL Database  Database Sir I have been reading Rose's india tutorial "Using MySQL Database with JSP/Servlet". In the Tutorial you have shown an example of backing up the database. When I tried to backup database
database connectivity using mysql
database connectivity using mysql  java file: eg1.java package eg...[]) throws SQLException { try { String connectionURL = "jdbc:mysql... seconds) I am using Netbeans 5.5, mysql server 5.0, to get data from table
PHP mysql database backup script - PHP
PHP mysql database backup script  How can i get the database backup using PHP mysql database
Error with LogIn with mysql database
Error with LogIn with mysql database  Hi, I have followed steps from your tutorial titled SpringMVClogin with database. I am not using Jetty, as I have Tomcat as my server using Eclipse IDE. When I run the program I get a Http
restore all mysql database:cPanel MYSQL 5.1 to 5.5
restore all mysql database:cPanel MYSQL 5.1 to 5.5  restore all mysql database:cPanel MYSQL 5.1 to 5.5
Repairing mysql database from command line
Repairing mysql database from command line  Hi, Can anyone tell me the process for repairing mysql database from command line? Thanks
how to import excel sheet into mysql database and save it as a table in database
how to import excel sheet into mysql database and save it as a table in database  sir, i want to import an excel sheet into a MySQL database and after importing it i want to store the excel sheet as a table in database
Upgrading Mysql 5.1 to 5.5 on existing database
Upgrading Mysql 5.1 to 5.5 on existing database  Upgrading Mysql 5.1 to 5.5 on existing database
MySQL Create Database
MySQL Create Database        ... to create the database on MySQL Server. MySQL Database server is one of the very... of the database server. MySQL comes with the easy to use the command line tool through
how to connect to database in php using mysql
how to connect to database in php using mysql  how to connect to database in php using mysql
retrieve data from mysql database
retrieve data from mysql database  hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant data from mysql database using php.... below my code is that.. <html> <head>
Creating a Database in MySQL
Creating a Database in MySQL       After establishing the connection with MySQL database by using.... In this example we are going to create a  database by MySQL and with the help
Data is not inserting correctly in mysql database.
Data is not inserting correctly in mysql database.  Hello Sir, below is my code to insert data into database by list iteration...( "jdbc:mysql://localhost:3306/asteriskcdrdb", "root", "techsoft
MySQL Database Training
MySQL Database Training        MySQL Training Course Objectives How... MySQL data with SQL. How to create a simple MySQL database Table
Image upload in mysql database using jsp servlet
Image upload in mysql database using jsp servlet  Hello, I need code to insert image in mysql database, I have seen the code which is already in your portal but it is not inserting image into database it save in the folder
Problem in uploading image to to mysql database
the record to mysql database. heres my code... index.jsp <%@ page...Problem in uploading image to to mysql database  Hi, need some help... be save in the database. and the image will also save in the desired folder. i
Problem in uploading image to to mysql database
the record to mysql database. heres my code... index.jsp <%@ page language...Problem in uploading image to to mysql database  Hi, need some help... be save in the database. and the image will also save in the desired folder. i

Ads