I have created to tables in mysql A with 1 column(and is primary key) and table B with 2 column(both primary key but one is pk of table A i.e foreign key) I want to create 2 jcombobox eg A and B so that when i select value in combobox A only values stored with A is shown in jcombobox eg If i select state mumbai it should only show the cities of mumbai I am trying this code Connection myconnection;
String path="jdbc:mysql://localhost/";
String place="start";
String username="root";
String password="";
try{
myconnection=DriverManager.getConnection(path+place, username, password);
try{
String query="Select * from state1 where states1=?";
PreparedStatement mystatement=myconnection.prepareStatement(query);
mystatement.setString(1, jComboBox1.getSelectedItem().toString());
ResultSet myresult=mystatement.executeQuery();
if(myresult.next())
{
do{
jComboBox1.addItem(myresult.getString("state"));
}
while(myresult.next());
}
}
I have stored some data in database table A but its not displaying in table B so i am unable to store data in table B.
Aucun commentaire:
Enregistrer un commentaire