Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using JComboBox value in as part of an SQL query

843854Feb 26 2003 — edited Feb 26 2003
Hi,
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 + "'";
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 26 2003
Added on Feb 26 2003
4 comments
245 views