Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT binding jComboBox to mysql database

Have Programming Question? Ask it here!
 
 
 


Fazil
binding jComboBox to mysql database
1 Answer(s)      5 years and 8 months ago
Posted in : Swing AWT



Advertisement
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
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
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
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
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.   import java.sql.
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
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
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
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
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
update mysql database
update mysql database  update mysql database
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
Database - mysql - SQL
Database - mysql size limit  What is the size limit for any mysql database
insert images into a Mysql database
insert images into a Mysql database  How can I insert images into a Mysql database
DYNAMIC BINDING
DYNAMIC BINDING  WHAT IS DYNAMIC BINDING
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
Binding in Flex
Binding in Flex  Hi....... Explain how binding works in mxml components? Please give the answer with example. Thanks  Ans: Binding in MXML Please see the following code: <s:Button id="btn" label
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
Binding in flex
Binding in flex  Hi......... Please tell me the Difference between...: 1. When we define a data binding in MXML it will use at compile time and we define a data binding in action script it will use at run time. 2. you use
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
issue on jcombobox
issue on jcombobox  i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox.only few values in the combobox need this functionality. need
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 mysql database
Context binding
Context binding  What is meant by Context binding?   A binding context is an object that holds data that you can reference from your... a hierarchy of binding contexts. The root level of the hierarchy refers to the viewModel
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using 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
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
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
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
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
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
JComboBox on JRadioButton - Java Beginners
JComboBox on JRadioButton  How to add JComboBox on Jpanel ,Give Me Sample Code
value and binding attribute
value and binding attribute  What is the difference between value and binding attribute of jsf tag
value and binding attribute
value and binding attribute  What is the difference between value and binding attribute in jsf
PHP mysql database backup script - PHP
PHP mysql database backup script  How can i get the database backup using PHP mysql database
XML data binding
XML data binding   hello, What is XML data binding?   hii, XML data binding refers to the process of representing the information in an XML document as an object in computer memory
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>
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
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
Advertisements
 

 

 

DMCA.com