1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class SQLInterface extends JFrame implements ActionListener {
public static final String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
public static final String PATH = "jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb); DBQ=BDTest.mdb; ";
public static final String USER = "";
public static final String PASSWORD = "";
private JTextArea ta;
private JTextField tf;
private SQLService sqls;
public SQLInterface() {
super("Interface SQL");
JPanel p = new JPanel(new BorderLayout());
ta = new JTextArea();
ta.setEditable(false);
ta.setMargin(new Insets(5, 5, 5, 5));
JScrollPane scrollPane = new JScrollPane(ta);
p.add(scrollPane, BorderLayout.CENTER);
tf = new JTextField();
tf.addActionListener(this);
p.add(tf, BorderLayout.SOUTH);
getContentPane().add(p);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
sqls.close();
System.exit(0);
}
});
setSize(800, 600);
setLocationRelativeTo(null);
show();
tf.requestFocus();
sqls = new SQLService(DRIVER, PATH, USER, PASSWORD);
}
public static void main(String[] args) {
SQLInterface x = new SQLInterface();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(tf)) {
ta.append("Exécution de: " + tf.getText() + "\n");
ta.append(sqls.exec(tf.getText()) + "\n");
tf.selectAll();
}
}
} |
Partager