希望您能够帮助我。我得到错误
“com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:'where 子句'中的未知列'Smith'”。
我有一个名为“aspirante”的数据库,它有一个名为“datos”的表(我已经填写了它)。在这里,我向您展示我是如何创建表格的:
CREATE TABLE `datos` (
`id_asp` int(11) NOT NULL AUTO_INCREMENT,
`ficha` mediumint(4) NOT NULL,
`apellido1` varchar(30) NOT NULL,
`apellido2` varchar(30) NOT NULL,
`nombre` varchar(50) NOT NULL,
`genero` char(1) NOT NULL,
`telefono1` varchar(20) NOT NULL,
`telefono2` varchar(20) NOT NULL,
`carrera` varchar(50) NOT NULL,
`promedio_sec` varchar(5) NOT NULL,
PRIMARY KEY (`id_asp`)
)
该方法看起来像这样。
void BuscarAspiranteEditar(String id) {
String sSQL = "";
String ap1 = "", ap2 = "", nom = "", gen = "", tel1 = "", tel2 = "", car = "", prom = "";
ConexionMySQL mysql = new ConexionMySQL();
Connection cn = mysql.Conectar();
sSQL = "SELECT id_asp, ficha, apellido1, apellido2, nombre, genero, telefono1, telefono2, promedio_sec FROM datos " +
"WHERE id_asp = "+id;
try {
Statement st = cn.createStatement();
ResultSet rs = st.executeQuery(sSQL);
while (rs.next()) {
ap1 = rs.getString("apellido1");
ap2 = rs.getString("apellido2");
nom = rs.getString("nombre");
gen = rs.getString("genero");
tel1 = rs.getString("telefono1");
tel2 = rs.getString("telefono2");
car = rs.getString("carrera");
prom = rs.getString("promedio_sec");
id_actualizar = id;
}
txtPrimerApellido.setText(ap1);
txtSegundoApellido.setText(ap2);
txtNombre.setText(nom);
txtPrimerTelefono.setText(tel1);
txtSegundoTelefono.setText(tel2);
txtCarrera.setText(car);
txtPromedio.setText(prom);
}
catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex);
}
}
我不喜欢Java,所以我希望你们能帮助我,我会很感激的。提前致谢!