Reputation: 39
I was trying to run this project i found on the internet but i get these errors in netbeans "com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: PROCEDURE contactos.sp_guardar does not exist" and they result from these two queries:
update db
String sql = "call sp_guardar(?,?,?,?,?)";
search db
String sql = "call buscar(?)";
Would love to be assisted on this.Am using a mysql database connected though xammp
The code for the project.
package contactosfx;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class AmigoDao implements AmigoInterface {
public AmigoDao(){
}
@Override
//UPDATE DB
public void guardar(Amigo amigo) {
Connection con = Conexion.conectar();
CallableStatement cs = null;
String sql = "call sp_guardar(?,?,?,?,?)";
try {
cs = con.prepareCall(sql);
cs.setString(1, amigo.getFoto());
cs.setString(2, amigo.getNombre());
cs.setString(3, amigo.getCorreo());
cs.setString(4, amigo.getTelf());
cs.setInt(5, amigo.getEstado());
cs.executeUpdate();
cs.close();
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
try {
if (con != null) {
cs.close();
con.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
@Override
public void actualizar(Amigo amigo, int id) {
Connection con = Conexion.conectar();
CallableStatement cs = null;
//String sql = "call sp_actualizar(?,?,?,?,?,?)";
try {
cs = con.prepareCall(sql);
cs.setString(1, amigo.getFoto());
cs.setString(2, amigo.getNombre());
cs.setString(3, amigo.getCorreo());
cs.setString(4, amigo.getTelf());
cs.setInt(5, amigo.getEstado());
cs.setInt(6, id);
cs.executeUpdate();
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
try {
if (!con.isClosed()) {
cs.close();
con.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
@Override
public ObservableList<Amigo> buscar(String nombres) {
Connection con = Conexion.conectar();
CallableStatement cs = null;
ResultSet rs = null;
ObservableList<Amigo> lista = FXCollections.observableArrayList();
String sql = "call buscar(?)";
//String sql = "call search(?)";
try {
cs = con.prepareCall(sql);
cs.setString(1, nombres);
rs = cs.executeQuery();
while(rs.next()){
lista.add(new Amigo(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getInt(6)));
}
} catch (SQLException ex) {
ex.printStackTrace();
}
return lista;
}
@Override
public ObservableList<Amigo> buscarHabilitados() {
Connection con = Conexion.conectar();
Statement st = null;
ResultSet rs = null;
String sql = "select*from habilitados";
ObservableList<Amigo> lista = FXCollections.observableArrayList();
try {
st = con.createStatement();
rs = st.executeQuery(sql);
while (rs.next()) {
lista.add(new Amigo(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getInt(6)));
}
} catch (SQLException e) {
e.printStackTrace();
}
return lista;
}
@Override
public ObservableList<Amigo> buscarDeshabilitados() {
Connection con = Conexion.conectar();
Statement st = null;
ResultSet rs = null;
String sql = "select*from deshabilitados";
ObservableList<Amigo> lista = FXCollections.observableArrayList();
try {
st = con.createStatement();
rs = st.executeQuery(sql);
while (rs.next()) {
lista.add(new Amigo(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getInt(6)));
}
} catch (SQLException e) {
e.printStackTrace();
}
return lista;
}
}
Upvotes: 1
Views: 141
Reputation: 6408
These are stored procedures that the writer of the code thought would be in the database. Apparently, they are not. To get this to work, you would need to implement the sp_guardar
and possibly the buscar
stored procedures or else remove them from the code.
Upvotes: 1