hello people. i have this application which is suppose to retrieve database tables form a paricular database being used and add them as items in2 a jcombobox.The reason is that i want to hvae the opportunity to insert a file into any table by just clicking my jcombobox and select the desired table to insert it into.

i went as much to write this to test since am doing this for the first time:

try {
JcomboBox jc = new JComboBox();
 Class.forName("com.mysql.jdbc.Driver").newInstance();
 System.out.println("It loaded ok");
Connection con = DriverManager.getConnection("jdbc:mysql://locahost:3306/db_name","root","");

 DatabaseMetaData dbmd = con.getMetaData();
 String[] tabtypes ={"TABLES"};
 System.out.println("");
 System.out.println("TABLE NAMES");
 System.out.println("-------------------------------");
 ResultSet rs = dbmd.getTables(null,null,null,tabtypes);
 while(rs.next())
 System.out.println(rs.getString("TABLE_NAME"_);
 jc.addItem(rs.getString("TABLE_NAME");
 }catch(Exception p){
 System.out.println("Exception: " + e.getMessage());

All i get is an error saying; "Illegal operation on an empty set". The most annoying thing is that there are tables present in the db but adding them as items.

Has anyone tried this before?i read a book and i read that some SQL softwares dont allow such access and i'm using MYSQL.

i need help badly.

Are u trying to fetch the table names only?
If Yes the query the database with "show table", after that get the records and add them as an item in jcombobox. and can u send me full code, i will help u. or just paste it here properly.

@Majestics: Yes i just want the database names because with what i'm doing,i want to have an opportunity where i or anyone who would like to use it can insert data to the database table i or they have selected from the comboBox.
i queried my table and i can see my tables,so adding them because i saw them from that angle aint proper for anyone who doesnt have that access.

As for the codes,what i posted is it but u can try and use it with the same mindset i have to see if it wokrs.if it does,show me the mistakes i have made and the necessary corections

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.