Neel
2012-04-05 05:43:58 UTC
I have written a small Java program using JDBC-ODBC object to do so but its not yet complete. It connects to the database but the create commands don't work.
Code:-
import java.io.*;
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
public class AccessDBCreator extends JFrame implements ActionListener
{
JFrame frame = new JFrame("Access Database Creator");
JLabel l1 = new JLabel("Query");
JTextArea ta1 = new JTextArea("");
JButton exec = new JButton("Execute");
JButton ext = new JButton("Exit");
JPanel p1 = new JPanel();
JLabel l2 = new JLabel("Status");
Connection con;
Statement st;
public AccessDBCreator()
{
frame.setLayout(new GridLayout(4,1));
frame.add(l1);
ta1.setLineWrap(true);
frame.add(ta1);
p1.add(exec);
p1.add(ext);
frame.add(p1);
frame.add(l2);
frame.setVisible(true);
frame.setSize(400,200);
ext.addActionListener(this);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbc");
con = DriverManager.getConnection("jdbc:odbc:test1");
st = con.createStatement();
System.out.println("\n\n *** Connection Successful ***");
}
catch(Exception e)
{
System.out.println("\n\n *** Connection Failed ***"+e);
}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == ext)
System.exit(0);
if(ae.getSource() == exec)
{
try
{
st.execute(ta1.getText());
}
catch(Exception e)
{
System.out.println(e);
}
}
}
public static void main(String args[])
{
AccessDBCreator adc = new AccessDBCreator();
}
}