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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
| package Frank;
import javax.swing.*;
import com.borland.dx.sql.dataset.*;
import com.borland.datastore.*;
import com.borland.dx.dataset.*;
import com.borland.dbswing.*;
import com.borland.jbcl.layout.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class InvoerUitslagen extends JPanel {
Database database = new Database();
QueryDataSet coureurs = new QueryDataSet();
XYLayout xYLayout1 = new XYLayout();
JdbNavComboBox cmb_gp = new JdbNavComboBox();
JdbNavComboBox cmb_coureurs = new JdbNavComboBox();
QueryDataSet gp = new QueryDataSet();
JComboBox cmb_punten = new JComboBox();
QueryDataSet punten = new QueryDataSet();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JButton jButton1 = new JButton();
String coureurr = "";
String gpx = "";
String puntenn = "";
int coureurid;
int gpid;
QueryDataSet tmp;
Statement statement;
public InvoerUitslagen() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
coureurs.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database, "select * from coureur ", null, true, Load.ALL));
database.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:Formule1", "", "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
this.setLayout(xYLayout1);
cmb_coureurs.setColumnName("naam");
cmb_coureurs.setDataSet(coureurs);
gp.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database, "select * from Race", null, true, Load.ALL));
cmb_gp.setActionCommand("comboBoxChanged");
cmb_gp.setColumnName("grand prix");
cmb_gp.setDataSet(gp);
cmb_punten.addItem(new String("10"));
cmb_punten.addItem(new String("8"));
cmb_punten.addItem(new String("6"));
cmb_punten.addItem(new String("5"));
cmb_punten.addItem(new String("4"));
cmb_punten.addItem(new String("3"));
cmb_punten.addItem(new String("2"));
cmb_punten.addItem(new String("1"));
cmb_punten.addItem(new String("0"));
punten.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database, "select * from Uitslag", null, true, Load.ALL));
xYLayout1.setWidth(412);
xYLayout1.setHeight(293);
jLabel1.setText("Grandprix");
jLabel2.setText("Coureur");
jLabel3.setText("Punten");
jButton1.setActionCommand("Voeg Punten Toe");
jButton1.setText("Voeg Punten Toe");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(MouseEvent e) {
jButton1_mouseReleased(e);
}
});
this.add(cmb_gp, new XYConstraints(207, 40, 178, 23));
this.add(cmb_coureurs, new XYConstraints(207, 100, 178, 23));
this.add(cmb_punten, new XYConstraints(207, 160, 178, 23));
this.add(jLabel1, new XYConstraints(34, 40, 125, 25));
this.add(jLabel2, new XYConstraints(34, 100, 125, 25));
this.add(jLabel3, new XYConstraints(34, 160, 125, 25));
this.add(jButton1, new XYConstraints(207, 220, 178, 23));
tmp = new QueryDataSet();
tmp.open();
}
void jButton1_mouseReleased(MouseEvent e) {
coureurr = cmb_coureurs.getSelectedItem().toString();
gpx = cmb_gp.getSelectedItem().toString();
puntenn = cmb_punten.getSelectedItem().toString();
coureurid = getId("coureur", "coureur_naam", coureurr);
gpid = getId("gp", "gp_naam", gpx);
try{
statement = database.createStatement();
boolean result = statement.execute("INSERT INTO resultaten (gp_id, coureur_id, punten) values ("+gpid+","+coureurid+","+punten+")");
cmb_coureurs.setSelectedIndex(0);
cmb_gp.setSelectedIndex(0);
cmb_punten.setSelectedIndex(0);
JOptionPane.showMessageDialog(null,"Record inserted successfully.");
statement.close();
}catch(SQLException sqlex){
JOptionPane.showMessageDialog(null,"Something went wrong when inserting the record, please try again.");
}
}
public int getId(String table, String kol, String val){
tmp.close();
tmp.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database, "SELECT id FROM "+table+" WHERE "+kol+"='" +val+ "'", null, true, Load.ALL));
tmp.executeQuery();
tmp.next();
return tmp.getInt(0);
}
} |