Connection to Excel using JDBC

Hi

I developed a program to send userid to excel sheet using jdbc...

While i opened excel sheet and try to send data through jdbc it works great ...

But the problem is while i closed the excel sheet and try to send data to excel sheet, it spells success.

But the data i entered is not in that excel sheet ...

What to do .?

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

publicclass InsertExcel

{

static JFrame frame;

static JPanel panel;

static JTextField textuserid;

static JTextField textfirstname;

static JTextField textlastname;

static JButton submit;

static JButton exit;

publicstaticvoid main(String args[])

{

frame =new JFrame("Inserting to excel sheet");;

panel =new JPanel();

JLabel labeluserid =new JLabel("User id ");

JLabel labelfirstname =new JLabel("First Name");

JLabel labellastname =new JLabel("Last Name");

textuserid =new JTextField(20);

textfirstname =new JTextField(20);

textlastname =new JTextField(20);

submit =new JButton("Submit to Excel sheet");

exit =new JButton("Exit");

panel.add(labeluserid);

panel.add(textuserid);

panel.add(labelfirstname);

panel.add(textfirstname);

panel.add(labellastname);

panel.add(textlastname);

panel.add(submit);

panel.add(exit);

frame.getContentPane().add(panel);

frame.setSize(1024,100);

frame.setVisible(true);

frame.setDefaultCloseOperation(3);

submit.addActionListener(new ActionListener()

{

publicvoid actionPerformed(ActionEvent e)

{

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con = DriverManager.getConnection("jdbc:odbc:Excel Files","","");

PreparedStatement stat2 = con.prepareStatement("insert into

[Book1$](USERID,FIRST_NAME,LAST_NAME) values (?,?,?)");

stat2.setString(1,textuserid.getText());

stat2.setString(2,textfirstname.getText());

stat2.setString(3,textlastname.getText());

stat2.executeUpdate();

JOptionPane.showMessageDialog(frame,new String("Successfully entered to excel sheet !!!"));

}

catch(Exception e1)

{

JOptionPane.showMessageDialog(frame,new String("Error while inserting to excel sheet !!! \n" +

e1));

}

}

});

exit.addActionListener(new ActionListener()

{

publicvoid actionPerformed(ActionEvent ex)

{

System.exit(0);

}

});

}

}

[4630 byte] By [Reona] at [2007-11-27 6:34:00]
# 1
I think this thread has been cross-posted
Jamwaa at 2007-7-12 18:00:08 > top of Java-index,Java Essentials,Java Programming...