
No puedo poner un boton de Eliminar en NetBeans
Publicado por Cristopher (9 intervenciones) el 09/08/2014 08:49:21
Buenas Noches, mi problema es que no me funciona ningun codigo para eliminar datos desde netbeans con base de datos MySQL y necesito de su ayuda porque soy novato, este es mi proyecto:
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
120
121
public class TblClientes extends javax.swing.JFrame {
TableRowSorter<TableModel> sorter;
DefaultTableModel m;
Connection con;
private Connection conexion() {
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/rcd","root","");
} catch (ClassNotFoundException | SQLException e) {
}
return con;
}
public TblClientes() {
initComponents();
FormatoClientes();
conexion();
setLocationRelativeTo(null);
txtBuscar.getDocument().addDocumentListener(
new DocumentListener() {
@Override
public void changedUpdate(DocumentEvent e) {
filtrar();
}
@Override
public void insertUpdate(DocumentEvent e) {
filtrar();
}
@Override
public void removeUpdate(DocumentEvent e) {
filtrar();
}
});
cargarClientes();
}
private void filtrar() {
RowFilter<TableModel, Object> rf = null;
int indiceColumnaTabla = 7;
switch (cboBuscar.getSelectedIndex()) {
case 0: indiceColumnaTabla = 1;break;
case 1: indiceColumnaTabla = 0;break;
case 2: indiceColumnaTabla = 2;break;
case 3: indiceColumnaTabla = 3;break;
case 4: indiceColumnaTabla = 4;break;
case 5: indiceColumnaTabla = 5;break;
case 6: indiceColumnaTabla = 6;break;
}
try {
rf = RowFilter.regexFilter("(?i)"+txtBuscar.getText(), indiceColumnaTabla);
} catch (java.util.regex.PatternSyntaxException e) {
}
sorter.setRowFilter(rf);
}
private void cargarClientes() {
try {
String titulos[] = {"Cód.", "Nombre", "Apellido(s)", "Ciudad", "Dirección", "Teléfono", "Celular", "Correo Electrónico"};
m = new DefaultTableModel(null, titulos);
JTable p = new JTable(m);
String fila[] = new String[8];
TblClientes.conectate obj = new TblClientes.conectate();
String consulta = "SELECT * FROM verclientes";
ResultSet r;
r = obj.Listar(consulta);
int c = 1;
while (r.next()) {
fila [0] = String.valueOf(c);
fila [1] = r.getString(1);
fila [2] = r.getString(2);
fila [3] = r.getString(3);
fila [4] = r.getString(4);
fila [5] = r.getString(5);
fila [6] = r.getString(6);
fila [7] = r.getString(7);
m.addRow(fila);
c++;
}
tblClientes.setModel(m);
sorter = new TableRowSorter<TableModel>(m);
tblClientes.setRowSorter(sorter);
this.tblClientes.setModel(m);
tblClientes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Error Al Extraer Los Datos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
}
}
private void FormatoClientes() {
tblClientes.getColumnModel().getColumn(0).setPreferredWidth(50);
tblClientes.getColumnModel().getColumn(1).setPreferredWidth(93);
tblClientes.getColumnModel().getColumn(2).setPreferredWidth(120);
tblClientes.getColumnModel().getColumn(3).setPreferredWidth(120);
tblClientes.getColumnModel().getColumn(4).setPreferredWidth(300);
tblClientes.getColumnModel().getColumn(5).setPreferredWidth(90);
tblClientes.getColumnModel().getColumn(6).setPreferredWidth(90);
tblClientes.getColumnModel().getColumn(7).setPreferredWidth(210);
}
private static class conectate {
public conectate() {
}
public ResultSet Listar(String Cad) {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/rcd", "root", "");
PreparedStatement da = con.prepareStatement(Cad);
ResultSet tbl = da.executeQuery();
return tbl;
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) {
javax.swing.JOptionPane.showMessageDialog(null, e.getMessage());
return null;
}
}
}
Valora esta pregunta


0