Using JComboBox value in as part of an SQL query
843854Feb 26 2003 — edited Feb 26 2003Hi,
Hopefully some one can help me here. What I'm trying to do is use a combo box to select a table name and then pass it into a SQL query. So if a user selects 'Student' from the combo box, the query is run against the Student table in the database. However I keep getting SQL errors saying the SQL statement is incomplete. Here is the code I'm using:
Combo box setup code
//create combo box and add items
String[] access = {"Student", "Teacher"};
accesslist = new JComboBox(access);
accesslist.setEditable(false);
accesslist.setSelectedIndex(0);
main code body
String acl = new String();
acl = (String)login.accesslist.getSelectedItem();
String query = "SELECT * FROM '" + acl + "' WHERE Username = '" + localuser + "'";