hi all ,
im trying to develop a small desktop database application so in my final step i wanted to set a code that give me the ability to import data from an excel file to my Mysql DB using Java so
i downloaded the jexcelapi and load it into my lib and then i set this code :

----- 1st class named : DBConnection.java---------
package javaapplication13;

/**
*
* @author DJO
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {
public Connection con;
public static void main(String args[]) {
Connection con =null;

try {
Class.forName("com.mysql.jdbc.Driver").newInstance ();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/DJO","root","root");


} catch(Exception exe) {
System.err.println("Exception: " + exe.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException exe) {System.out.println("fof " + exe);}
}
}

}
----------------------------------
2scnd class : ExToMy.java
----------------------------------

import jxl.*;
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class ExToMy extends JFrame implements ActionListener{
/*swing components*/
private JLabel l_xlfile,l_xlsheets,l_mytables;
private JTextField xlfile;
private JComboBox xlsheets,mytables;
private JButton browse,convert,reload_file;
private JFileChooser filechoose;
private GridBagLayout gbl;
private GridBagConstraints gbc;
/*swing components*/
java.util.List my_fields_type;
/*DB*/
DBConnection db;
Statement stat;
ResultSet rs;
/*DB*/
/*excel*/
Workbook workbook;
private String[] sheet_names;
/*excel*/
public ExToMy(){
initComponents();
/*DB*/
try{
db=new DBConnection();
stat=db.con.createStatement();
}
catch(Exception exe){}
initDB();
/*DB*/
/*Layout settings*/
gbl=new GridBagLayout();
gbc=new GridBagConstraints();
gbc.weighty=1;
gbc.weightx=1;
gbc.fill=GridBagConstraints.HORIZONTAL;
posComponent(l_xlfile,gbl,gbc,1,1);
posComponent(l_xlsheets,gbl,gbc,1,3);
posComponent(l_mytables,gbl,gbc,1,4);
posComponent(xlfile,gbl,gbc,2,1);
gbc.fill=GridBagConstraints.NONE;
gbc.anchor=GridBagConstraints.NORTHWEST;
posComponent(reload_file,gbl,gbc,1,2);
posComponent(browse,gbl,gbc,2,2);
gbc.anchor=GridBagConstraints.CENTER;
gbc.fill=GridBagConstraints.HORIZONTAL;
posComponent(xlsheets,gbl,gbc,2,3);
posComponent(mytables,gbl,gbc,2,4);
gbc.fill=GridBagConstraints.NONE;
posComponent(convert,gbl,gbc,2,5);
gbc.fill=GridBagConstraints.HORIZONTAL;
setLayout(gbl);
setTitle("Excel to mysql Converter");
setSize(500,500);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/*Layout settings*/
}
public void initComponents(){
l_xlfile=new JLabel("Select a ms excel file to open");
l_xlsheets=new JLabel("Worksheets in workbook");
l_mytables=new JLabel("MySQL tables");
xlfile=new JTextField();
xlsheets=new JComboBox();
mytables=new JComboBox();
browse=new JButton("Browse");
browse.addActionListener(this);
reload_file=new JButton("Reload File");
reload_file.addActionListener(this);
convert=new JButton("Convert");
convert.addActionListener(this);
filechoose=new JFileChooser();
my_fields_type=new ArrayList();
}
public void initDB(){
try{
mytables.removeAllItems();
rs=stat.executeQuery("SHOW TABLES");
while(rs.next()){
mytables.addItem(""+rs.getString(1));
}
}
catch(Exception exe){System.out.println(""+exe);}
}
public void posComponent(Component comp,GridBagLayout gbl,GridBagConstraints
gbc,int posx,int posy){
gbc.gridx=posx;
gbc.gridy=posy;
gbl.setConstraints(comp,gbc);
getContentPane().add(comp);
}
public void openXls(){
int val=filechoose.showOpenDialog(this);
if(val == JFileChooser.APPROVE_OPTION) {
/*excel*/
try{
workbook=
Workbook.getWorkbook(filechoose.getSelectedFile()) ;
xlfile.setText(filechoose.getSelectedFile().getPat h());
sheet_names=workbook.getSheetNames(); //A stringarray of sheet names is returned
xlsheets.removeAllItems();
for(int i=0;i<sheet_names.length;i++){
xlsheets.addItem(""+sheet_names[i]);
}
}
catch(Exception
exe){JOptionPane.showMessageDialog(this,(String)"S elect a valid excel(.xls)file");}
}
}
public void actionPerformed(ActionEvent ev){
Object source=ev.getSource();
if(source==browse){
openXls();
}
if(source==reload_file){
try{
workbook=
Workbook.getWorkbook(filechoose.getSelectedFile()) ;
sheet_names=workbook.getSheetNames(); //A string array ofsheet names is returned
xlsheets.removeAllItems();
for(int i=0;i<sheet_names.length;i++){
xlsheets.addItem(""+sheet_names[i]);
}
}
catch(Exception exe){}
}
if(source==convert){
if(xlsheets.getItemCount()<=0){
JOptionPane.showMessageDialog(this,(String)"Select a validexcel(.xls) file to select a worksheet");
}
else{
try{
int xl_fields=0,my_fields=0,xl_row_count=0;
String insert_query="";
String
sel_sheet_name=""+xlsheets.getSelectedItem();
String
sel_table_name=""+mytables.getSelectedItem();
if(sel_sheet_name.equals(sel_table_name)){
Sheet
sheet=workbook.getSheet(xlsheets.getSelectedIndex( ));
xl_fields=sheet.getColumns();
my_fields_type.clear();
rs=stat.executeQuery("DESCRIBE"+sel_table_name);
while(rs.next()){
my_fields++;
my_fields_type.add(rs.getString(2));
}
if(xl_fields==my_fields){
//JOptionPane.showMessageDialog(this,(String)"Number of Fields are equal");
xl_row_count=sheet.getRows();
System.out.println(xl_row_count);//
for(int j=0;j<xl_row_count;j++){
insert_query="INSERT INTO"+sel_table_name+" VALUES(";
for(int i=0;i<xl_fields;i++){
String
field_type=""+my_fields_type.get(i);
if(field_type.indexOf("int")>=0||field_type.indexO f("float")>=0||
field_type.indexOf("double")>=0){
insert_query+=sheet.getCell(i,j).getContents().toS tring()+",";
}
else{
insert_query+="\'"+sheet.getCell(i,j).getContents( )+"\',";
}
}
insert_query=insert_query.substring(0,insert_query .length()-1)+")";
System.out.println(insert_query);
try{
stat.executeUpdate(insert_query);
}
catch(Exception
exe){JOptionPane.showMessageDialog(this,(String)"R ow No "+j+""+exe);System.out.println(""+exe);}
}
JOptionPane.showMessageDialog(this,(String)"All rows Successfully copied");
}
else
JOptionPane.showMessageDialog(this,(String)"Number of Fields are notequal");
}
else
JOptionPane.showMessageDialog(this,(String)"Select same worksheet name asmysql table");
}
catch(Exception exe){System.out.println(""+exe);}
}
}
}
public static void main(String[] args){
ExToMy exm=new ExToMy();
}
}

----------------

the problem now is when i run ExToMy class it runs with success and im able to choose my excel file but i m not able to see the tables in the JLabel MySQL tables" , it's empty and i have more than 3 tables but nothing is shown ;
so please if anyone found the error or have the solution i will be so much thankful ! :confused::confused::confused: