I am following a tutorial (Client System) trying to make a CRUD system using Java and for the database MySQL. The thing is that the tutorial was made in Java/ORACLE so in the part to add a client to the database i am getting some errors (i have been searching a solution before posting this but i can't understand how to make it works)
This is my code
public String agregarCliente(Connection con , Cliente cli)
{
PreparedStatement pst = null;
String sql = "INSERT INTO clientes (IDCLIENTE, NOMBRES, APELLIDOS, GENERO) "
+ "VALUES(CLIENTE_SEQ.NEXTVAL, ?, ?, ?)";
try
{
pst = con.prepareStatement(sql);
pst.setString(1, cli.getNombres());
pst.setString(2, cli.getApellidos());
pst.setString(3, cli.getGenero()+"");
mensaje = "CLIENTE GUARDADO CORRECTAMENTE";
pst.execute();
pst.close();
}
catch (SQLException e)
{
// REST OF THE CODE
}
return mensaje;
}
What do i have to replace CLIENTE_SEQ.NEXTVAL ? I can't create a sequence in MySQL, and don't know how to get the latest Client ID. Consider IDCLIENTE is declared as auto-incremented.
If i leave only 3 question marks " + "VALUES(?, ?, ?)"; " i get
Column count doesn't match value count at row 1
If i leave 3 question marks and 3 values in the table
String sql = "INSERT INTO clientes (NOMBRES, APELLIDOS, GENERO) "
+ "VALUES(?, ?, ?)";
it says that the client was added succefully but when i do a select * from clientes; it says it's empty :S